public function extend($id, callable $callback)
    {
        if (!$this->has($id)) {
            throw new Exception\NotFoundException;
        }
        $oldCallback = $this->callbacks[$id];
        $this->callbacks[$id] = function () use ($oldCallback, $callback, $id) {
            if (!$this->isReady($id)) {
                $thisFunction = $this->callbacks[$id];
                $this->callbacks[$id] = $oldCallback;
                $this->instantiate($id);
                $this->callbacks[$id] = $thisFunction;
            }
            $instance = $this->instances[$id];
            $newInstance = call_user_func($callback, $instance, $this);
            return $newInstance ?: $instance;
        };
        if ($this->isReady($id)) {
            $instance = $this->instances[$id];
            $newInstance = call_user_func($callback, $instance, $this);
            $this->instances[$id] = $newInstance ?: $instance;
        }
        return $this;
    }
public function extend($id, callable $callback)
    {
        if (!$this->has($id)) {
            throw new Exception\NotFoundException;
        }
        $oldCallback = $this->callbacks[$id];
        $this->callbacks[$id] = function () use ($oldCallback, $callback, $id) {
            if (!$this->isReady($id)) {
                $thisFunction = $this->callbacks[$id];
                $this->callbacks[$id] = $oldCallback;
                $this->instantiate($id);
                $this->callbacks[$id] = $thisFunction;
            }
            $instance = $this->instances[$id];
            $newInstance = call_user_func($callback, $instance, $this);
            return $newInstance ?: $instance;
        };
        if ($this->isReady($id)) {
            $instance = $this->instances[$id];
            $newInstance = call_user_func($callback, $instance, $this);
            $this->instances[$id] = $newInstance ?: $instance;
        }
        return $this;
    }
public function extend ( $ id , callable $ callback ) { if ( ! $ this -> has ( $ id ) ) { throw new Exception \ NotFoundException ; } $ oldCallback = $ this -> callbacks [ $ id ] ; $ this -> callbacks [ $ id ] = function ( ) use ( $ oldCallback , $ callback , $ id ) { if ( ! $ this -> isReady ( $ id ) ) { $ thisFunction = $ this -> callbacks [ $ id ] ; $ this -> callbacks [ $ id ] = $ oldCallback ; $ this -> instantiate ( $ id ) ; $ this -> callbacks [ $ id ] = $ thisFunction ; } $ instance = $ this -> instances [ $ id ] ; $ newInstance = call_user_func ( $ callback , $ instance , $ this ) ; return $ newInstance ? : $ instance ; } ; if ( $ this -> isReady ( $ id ) ) { $ instance = $ this -> instances [ $ id ] ; $ newInstance = call_user_func ( $ callback , $ instance , $ this ) ; $ this -> instances [ $ id ] = $ newInstance ? : $ instance ; } return $ this ; }
Extends existing service.

@param string $id
@param callable $callback accepts extended service instance as first argument and container as second
@return $this
Extends existing service .