yii\di\Container::invoke PHP Method

invoke() public method

This methods allows invoking a callback and let type hinted parameter names to be resolved as objects of the Container. It additionally allow calling function using named parameters. For example, the following callback may be invoked using the Container to resolve the formatter dependency: php $formatString = function($string, \yii\i18n\Formatter $formatter) { ... } Yii::$container->invoke($formatString, ['string' => 'Hello World!']); This will pass the string 'Hello World!' as the first param, and a formatter instance created by the DI container as the second param to the callable.
Since: 2.0.7
public invoke ( callable $callback, array $params = [] ) : mixed
$callback callable callable to be invoked.
$params array The array of parameters for the function. This can be either a list of parameters, or an associative array representing named function parameters.
return mixed the callback return value.
    public function invoke(callable $callback, $params = [])
    {
        if (is_callable($callback)) {
            return call_user_func_array($callback, $this->resolveCallableDependencies($callback, $params));
        } else {
            return call_user_func_array($callback, $params);
        }
    }