Inpsyde\MultilingualPress\Service\AddOnlyContainer::extend PHP Method

extend() public method

The new factory callback will receive as first argument the object created by the current factory, and as second argument the container.
Since: 3.0.0
public extend ( string $name, callable $new_factory ) : static
$name string The name of an existing factory callback.
$new_factory callable The new factory callback.
return static Container instance.
    public function extend($name, callable $new_factory)
    {
        if ($this->is_locked) {
            throw ContainerLockedException::for_name($name, 'extend');
        }
        if (!array_key_exists($name, $this->factories)) {
            throw ContainerValueNotSetException::for_name($name, 'extend');
        }
        if (array_key_exists($name, $this->values)) {
            throw ContainerValueAlreadySetException::for_name($name, 'extend');
        }
        $current_factory = $this->factories[$name];
        $this->factories[$name] = function (Container $container) use($new_factory, $current_factory) {
            return $new_factory($current_factory($container), $container);
        };
        return $this;
    }