Extends the existing object.

@param string $key
@param callable|Closure $callable $callable
@return callable
165719
public function extend(string $key, Closure $callable)
    {
        if (!isset($this->stack[$key])) {
            throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $key));
        }

        if (!$callable instanceof Closure) {
            throw new InvalidArgumentException(
                sprintf('Identifier "%s" is not Closure Object.', $callable)
            );
        }

        $binding = $this->offsetExists($key) ? $this->stack[$key] : null;

        $extended = function () use ($callable, $binding) {
            if (!is_object($binding)) {
                throw new ContainerException(sprintf('"%s" must be Closure object.', $binding));
            }

            return $callable($binding($this), $this);
        };

        return $this[$key] = $extended;
    }
891145
public function map(callable $callable)
    {
        $keys = array_keys($this->items);
        $results = array_map($callable, $this->items, $keys);

        return new self($results);
    }
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;
    }
223809
public function extend(Closure $callback)
    {
        $instance = $this->retrieve();
        call_user_func($callback, $instance);

        return $instance;
    }
100933
public function service($name, $callable) {

        $this->registry[$name] = function($c) use($callable) {
            static $object;

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

            return $object;
        };

        return $this;
    }
1080947
public static function is_callable( $key )
	{
		if ( is_callable( $key ) )
		{
			return true;
		}

		if ( array_key_exists( $key, static::$_container ) )
		{
			return true;
		}

		return false;
	}
790013
public function call(callable $callable, array $args = [])
    {
        if (is_string($callable) && strpos($callable, '::') !== false) {
            $callable = explode('::', $callable);
        }

        if (is_array($callable)) {
            if (is_string($callable[0])) {
                $callable[0] = $this->getContainer()->get($callable[0]);
            }

            $reflection = new ReflectionMethod($callable[0], $callable[1]);

            if ($reflection->isStatic()) {
                $callable[0] = null;
            }

            return $reflection->invokeArgs($callable[0], $this->reflectArguments($reflection, $args));
        }

        if (is_object($callable)) {
            $reflection = new ReflectionMethod($callable, '__invoke');

            return $reflection->invokeArgs($callable, $this->reflectArguments($reflection, $args));
        }

        $reflection = new ReflectionFunction($callable);

        return $reflection->invokeArgs($this->reflectArguments($reflection, $args));
    }
742777
public function map( $callable ) {
		$elements = array();
		$type = null;
		foreach ( $this->elements as $element ) {
			$result = call_user_func( $callable, $element );

			if ( null === $type ) {
				$type = gettype( $result );

				if ( 'object' === $type ) {
					$type = get_class( $result );
				}
			}

			$elements[] = $result;
		}

		return $this->new_from_trusted( $elements, $type ? : $this->get_type() );
	}
551014
private function extended(callable $previous = null, callable $current): callable
    {
        return is_null($previous) ? $current : new Extension($current, $previous);
    }
622941
public static function getKey($callable)
    {
        /** @var string|null $class */
        $class = null;
        /** @var string|null $method */
        $method = null;

        if (is_string($callable)) {
            $method = $callable; // works for 'Cls::method' case as well
        } elseif (is_array($callable)) {
            $class = is_object($callable[0]) ? get_class($callable[0]) : $callable[0];
            $method = $callable[1];
        } elseif (is_object($callable)) {
            if ($callable instanceof \ReflectionFunctionAbstract) {
                if ($callable->isClosure()) {
                    return null;
                }

                $class = $callable instanceof \ReflectionMethod ? $callable->class : null;
                $method = $callable->name;
            } else {
                if ($callable instanceof \Closure) {
                    return null;
                }

                $class = get_class($callable);
                $method = '__invoke';
            }
        }

        return strtolower(($class ? $class . '::' : '') . $method);
    }
947926
public function add($callable)
    {
        $callable = $this->resolveCallable($callable);
        if ($callable instanceof Closure) {
            $callable = $callable->bindTo($this->container);
        }

        $this->middleware[] = $callable;

        return $this;
    }
132087
public function mapWithKeys(callable $callback): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) use ($callback) {
            foreach ($data as $key => $value) {
                /** @var iterable $result */
                $result = $callback($value, $key);

                foreach ($result as $resultKey => $resultValue) {
                    yield $resultKey => $resultValue;
                }
            }
        });
    }
1198944
public static function create(iterable $iterable, $callable = null): ISeq
    {
        if ($callable !== null) {
            $callable = (new CallbackParser(InvalidArgumentException::class))->parseArrowFunction($callable);

            return new static(function () use ($iterable, $callable) {
                foreach ($iterable as $i) {
                    $item = $callable($i);

                    if (is_iterable($item)) {
                        yield from $item;
                    } else {
                        yield $item;
                    }
                }
            });
        }

        return new static($iterable);
    }
808195
public function call($key, $callable)
    {
        if (!is_callable($callable)) {
            throw new \InvalidArgumentException('Not a valid callable.');
        }

        if ($this->exists($key)) {
            return $this->get($key);
        }

        $args = func_get_args();
        array_shift($args);
        array_shift($args);

        $value = call_user_func_array($callable, $args);

        $this->set($key, $value);

        return $value;
    }
931448
public function register($key, $callable)
	{
		if (!$this->has($key) && is_callable($callable))
		{
			self::$registry[$key] = $callable;
			return true;
		}

		return false;
	}
127270
static function prototype(callable $callable) {
        /** @var \ReflectionMethod|\ReflectionFunction  $prototype */
        
        if(\is_array($callable)) {
            $prototype = new \ReflectionMethod($callable[0], $callable[1]);
        } else {
            $prototype = new \ReflectionFunction($callable);
        }
        
        $signature = '';
        
        /** @var \ReflectionParameter  $param */
        foreach($prototype->getParameters() as $param) {
            $type = $param->getType();
            $signature .= ($type->allowsNull() ? '?' : '').$type->getName().($param->isOptional() ? '?' : '').',';
        }
        
        $signature = \substr($signature, 0, -1);
        
        $return = $prototype->getReturnType();
        if($return !== null) {
            $signature .= '='.($return->allowsNull() ? '?' : '').$return->getName();
        }
        
        if(empty($signature)) {
            throw new \InvalidArgumentException('Given callable has no signature to build');
        }
        
        return $signature;
    }
247212
public function add($key, $callable = null)
    {
        if (null !== $callable) {
            $group = new PermissionGroup($callable);
            $group->key($key);

            $this->permissions->put($key, $group);
        } else {
            $group = new PermissionGroup();

            $group->key($key);
            $this->permissions->put($key, $group);
        }
        return $group;
    }