Extends a service definition.

Useful when you want to extend an existing object definition,
without necessarily loading that object.

@param string   $id
@param callable $callable
@return $this
@throws \InvalidArgumentException
514315
public function extend(string $id, callable $callable)
    {
        if ($this->frozen) {
            throw new FrozenContainerException(
                "The container is frozen and is not possible to extend the service \"{$id}\"."
            );
        }

        $id = $this->getRealId($id);

        if (!array_key_exists($id, $this->definitions)) {
            throw new \InvalidArgumentException("The service \"{$id}\" does not exist.");
        }

        if (!isset($this->extensionQueues[$id])) {
            $this->extensionQueues[$id] = new ExtensionQueue($this);
        }

        $this->extensionQueues[$id]->add($callable);

        return $this;
    }
937851
public function bind($id, callable $serviceGenerator)
    {
        $this->callables[(string)$id] = function ($zit) use ($serviceGenerator) {
            static $object;

            if (null === $object) {
                $object = $serviceGenerator($zit);
            }

            return $object;
        };
    }
254794
public function get($id)
    {
        try {
            $handler = $this->resolve($id);

            if ($handler instanceof RequestHandlerInterface) {
                return $handler;
            }

            return new CallableHandler($handler);
        } catch (NotFoundExceptionInterface $exception) {
            throw $exception;
        } catch (Exception $exception) {
            throw new class("Error getting the handler $id", 0, $exception) extends Exception implements
                ContainerExceptionInterface {
            };
        }
    }
554206
public function get($id)
  {
    if (isset($this->instances[$id])) return $this->instances[$id];
    if (isset($this->callables[$id]))
    {
      $item = call_user_func($this->callables[$id],$this);
      return $this->instances[$id] = $item;
    }
    throw new \InvalidArgumentException(sprintf('Identifier "%s" is not defined for get.', $id));
  }
251989
public function setCallable(string $id, callable $callable, bool $multi = false, array $arguments = []): self
    {
        return $this->set($id, new Definition\Callable_($callable, $arguments), $multi);
    }
1278846
public function addEvent($event, $callable)
    {
        if (!is_callable($callable)) {
            throw new \InvalidArgumentException(
                sprintf(
                    '%s expects parameter 2 to be callable, %s given: %s',
                    __METHOD__,
                    gettype($callable),
                    print_r($callable, true)
                )
            );
        }

        if (!isset($this->events[$event])) {
            $this->events[$event] = array();
        }

        $this->events[$event][] = $callable;
    }
663010
public function extend($id, callable $extender)
    {
        if (!$this->has($id)) {
            throw new NotFoundException('Alias (' . $id . ') is not being managed by the container');
        }

        $this->extenders[$id][] = $extender;
    }
188198
public function add($key, $callable)
    {
        $menu = new AdminMenu($callable);

        $this->adminMenu->put($key, $menu);

        return $this;
    }
1648
public function extend($name, $callable, $strict = true)
    {
        if (!$this->services->has($name)) {
            if ($strict) {
                throw new InvalidArgumentException(sprintf('Service "%s" is not defined.', $name));
            } else {
                return false;
            }
        }

        $factory = $this->services->get($name);

        if (!is_object($factory) || !method_exists($factory, '__invoke')) {
            throw new InvalidArgumentException(sprintf('Service "%s" does not contain an object definition.', $name));
        }

        if (!is_object($callable) || !method_exists($callable, '__invoke')) {
            throw new InvalidArgumentException('Extension service definition is not a Closure or invokable object.');
        }

        $extended = function($c) use($callable, $factory) {
            /** @var Closure $factory */
            return $callable($factory($c), $c);
        };

        if ($this->factories->contains($factory)) {
            $this->factories->detach($factory);
            $this->factories->attach($extended);
        }

        $this->services->unlock($name);
        $this->services->set($name, $extended);

        return $this->services->get($name);
    }
581238
public function extend(string $offset, callable $callable): callable
    {
        isset($this->keys[$offset])
            || Exception::unknownProperty($offset);
        isset($this->frozen[$offset])
            && Exception::overrideService($offset);
        is_object($this->items[$offset])
            || Exception::unknownMethod('__invoke');
        method_exists($this->items[$offset], '__invoke')
            || Exception::unknownMethod('__invoke');
        isset($this->protect[$this->items[$offset]])
            && Exception::permission($offset);
        is_object($callable)
            || Exception::unknownMethod('__invoke');
        method_exists($callable, '__invoke')
            || Exception::unknownMethod('__invoke');

        $factory = $this->items[$offset];
        $extended = function ($c) use ($callable, $factory) {
            return $callable($factory($c), $c);
        };
        if (isset($this->factory[$factory])) {
            $this->factory->detach($factory);
            $this->factory->attach($extended);
        }
        return $this[$offset] = $extended;
    }
1025773
private static function reg($callable)
    {
        $id = debug_backtrace()[2]['function'];
        if (! self::getInstance()->offsetExists($id)) {
            self::getInstance()->offsetSet($id, $callable);
        }
        return self::getInstance()->offsetGet($id);
    }
316056
public static function share($callable)
    {
        if (!is_object($callable) || !method_exists($callable, '__invoke')) {
            throw new InvalidArgumentException('Callable is not a Closure or invokable object.');
        }
        
        return function ($c) use ($callable) {
            static $object;

            if (null === $object) {
                $object = $callable($c);
            }

            return $object;
        };
    }
305138
public function callable(callable $callable): BaseQueryRelateContract
    {
        $query = call_user_func($callable, $this->query);
        if ($query instanceof Builder) {
            $this->query = $query;
        }

        return $this;
    }
1097127
public function fn($id, $callable = null, $needsContainer = false)
    {
        if ($callable === null) {
            $callable = $id;
        }
        if (!is_callable($callable)) {
            throw new \InvalidArgumentException("Not callable");
        }
        $this->set($id, array($callable, $needsContainer));
    }
1175910
public function _and(callable $callable = null)
    {
        $history = $this->whereNeedAddAndOrOr;
        $this->whereNeedAddAndOrOr = 1;

        if (is_callable($callable)) {
            $history === 0 && $this->whereNeedAddAndOrOr = 0;
            $this->lBrackets();
            call_user_func($callable, $this);
            $this->rBrackets();
        }

        return $this;
    }
238337
public function set($id, callable $resolver)
    {
        $this->innerSet($id, $resolver);
        unset($this->resolved[$id]);
        unset($this->singletons[$id]);
        return $this;
    }
195643
protected function instantiate($id)
    {
        $this->instances[$id] = call_user_func($this->callbacks[$id], $this);
    }