public function addToContext( string $key, $value, string $behavior ): View
    {
        switch ($behavior) {
            case View::REPLACE:
                $this->_context_[$key] = $value;
                return $this;
            case View::MERGE:
                if(array_key_exists($key, $this->_context_)) {
                    $this->_context_ = array_merge_recursive($this->_context_, [$key => $value]);
                    return $this;
                }
                $this->_context_[$key] = $value;
                return $this;
            case View::ADD_ONLY:
                if (array_key_exists($key, $this->_context_)) {
                    return $this;
                }
                $this->_context_[$key] = $value;
                return $this;
            case View::REPLACE_ONLY:
                if (! array_key_exists($key, $this->_context_)) {
                    return $this;
                }
                $this->_context_[$key] = $value;
                return $this;
            case View::MERGE_ONLY:
                if (! array_key_exists($key, $this->_context_)) {
                    return $this;
                }
                $this->_context_ = array_merge_recursive($this->_context_, [$key => $value]);
                return $this;
            default:
                throw new InvalidContextAddingBehavior(
                    sprintf(
                        _('Invalid behavior "%s" for adding to the context of view "%s".'),
                        $key,
                        $this->_uri_
                    )
                );
        }
    }
public function addToContext( string $key, $value, string $behavior ): View
    {
        switch ($behavior) {
            case View::REPLACE:
                $this->_context_[$key] = $value;
                return $this;
            case View::MERGE:
                if(array_key_exists($key, $this->_context_)) {
                    $this->_context_ = array_merge_recursive($this->_context_, [$key => $value]);
                    return $this;
                }
                $this->_context_[$key] = $value;
                return $this;
            case View::ADD_ONLY:
                if (array_key_exists($key, $this->_context_)) {
                    return $this;
                }
                $this->_context_[$key] = $value;
                return $this;
            case View::REPLACE_ONLY:
                if (! array_key_exists($key, $this->_context_)) {
                    return $this;
                }
                $this->_context_[$key] = $value;
                return $this;
            case View::MERGE_ONLY:
                if (! array_key_exists($key, $this->_context_)) {
                    return $this;
                }
                $this->_context_ = array_merge_recursive($this->_context_, [$key => $value]);
                return $this;
            default:
                throw new InvalidContextAddingBehavior(
                    sprintf(
                        _('Invalid behavior "%s" for adding to the context of view "%s".'),
                        $key,
                        $this->_uri_
                    )
                );
        }
    }
public function addToContext ( string $ key , $ value , string $ behavior ) : View { switch ( $ behavior ) { case View :: REPLACE : $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: MERGE : if ( array_key_exists ( $ key , $ this -> _context_ ) ) { $ this -> _context_ = array_merge_recursive ( $ this -> _context_ , [ $ key => $ value ] ) ; return $ this ; } $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: ADD_ONLY : if ( array_key_exists ( $ key , $ this -> _context_ ) ) { return $ this ; } $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: REPLACE_ONLY : if ( ! array_key_exists ( $ key , $ this -> _context_ ) ) { return $ this ; } $ this -> _context_ [ $ key ] = $ value ; return $ this ; case View :: MERGE_ONLY : if ( ! array_key_exists ( $ key , $ this -> _context_ ) ) { return $ this ; } $ this -> _context_ = array_merge_recursive ( $ this -> _context_ , [ $ key => $ value ] ) ; return $ this ; default : throw new InvalidContextAddingBehavior ( sprintf ( _ ( 'Invalid behavior "%s" for adding to the context of view "%s".' ) , $ key , $ this -> _uri_ ) ) ; } }
Add information to the context.

@param string $key      Context key to add.
@param mixed  $value    Value to add under the given key.
@param string $behavior Behavior to use for adapting the context.
@return View
Add information to the context .