public function extend($name, $extender)
    {
        if (!is_callable($extender, true)) {
            throw new FactoryUncallableException('$extender must appear callable');
        }

        if (!array_key_exists($name, $this->factories)) {
            throw new NotFoundException("No factory available for: $name");
        }

        $factory = $this->factories[$name];

        $newFactory = function (Container $c) use ($extender, $factory) {
            return call_user_func($extender, call_user_func($factory, $c), $c);
        };

        $this->setFactory($name, $newFactory);

        return $newFactory;
    }
public function extend($name, $extender)
    {
        if (!is_callable($extender, true)) {
            throw new FactoryUncallableException('$extender must appear callable');
        }

        if (!array_key_exists($name, $this->factories)) {
            throw new NotFoundException("No factory available for: $name");
        }

        $factory = $this->factories[$name];

        $newFactory = function (Container $c) use ($extender, $factory) {
            return call_user_func($extender, call_user_func($factory, $c), $c);
        };

        $this->setFactory($name, $newFactory);

        return $newFactory;
    }
public function extend ( $ name , $ extender ) { if ( ! is_callable ( $ extender , true ) ) { throw new FactoryUncallableException ( '$extender must appear callable' ) ; } if ( ! array_key_exists ( $ name , $ this -> factories ) ) { throw new NotFoundException ( "No factory available for: $name" ) ; } $ factory = $ this -> factories [ $ name ] ; $ newFactory = function ( Container $ c ) use ( $ extender , $ factory ) { return call_user_func ( $ extender , call_user_func ( $ factory , $ c ) , $ c ) ; } ; $ this -> setFactory ( $ name , $ newFactory ) ; return $ newFactory ; }
Add a function that gets applied to the return value of an existing factory

@note A cached value (from a previous property read) will thrown away. The next property read
(and all new_NAME() calls) will call the original factory.

@param string   $name     The name of the value
@param callable $extender Function that is applied to extend the returned value
@return \Closure
@throws FactoryUncallableException|NotFoundException
Add a function that gets applied to the return value of an existing factory