$key : $default_value; } /** * Set context items by key. * * @param string $key Context key. * @param mixed $value Context value. * * @return void */ public function set( $key, $value ) { if ( property_exists( $this, $key ) ) { $this->$key = $value; } } /** * Reset context items by key. * * @param string $key Context key. * * @return void */ public function reset( $key ) { if ( property_exists( $this, $key ) ) { $this->$key = null; } } /** * Reset all context items. * * @return void */ public function reset_all() { foreach ( $this->allowed_properties as $key ) { $this->reset( $key ); } } /** * Push to stack. * * @param string $key Context key. * @param mixed $value Context value. * * @return void */ public function push_to_stack( $key, $value ) { if ( property_exists( $this, $key ) ) { $values = $this->get( $key, [] ); $values[] = $value; $this->set( $key, $values ); } } /** * Pop from stack. * * @param string $key Context key. * * @return mixed */ public function pop_from_stack( $key ) { if ( property_exists( $this, $key ) ) { $values = $this->get( $key, [] ); if ( empty( $values ) ) { return null; } $value = array_pop( $values ); $this->set( $key, $values ); return $value; } return null; } /** * Check if stack is empty. * * @param string $key Context key. * * @return bool */ public function is_empty( $key ) { $value = $this->get( $key ); return ! isset( $value ) || empty( $value ); } }