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;
}