src/Invoker.php
public function invoke($callable, array $namedParams = [], array $classParams = [])
    {
        $classParams = $this->reindexclassParams($classParams);

        if ($callable instanceof \Closure) {
            return $this->invokeFunction($callable, $namedParams, $classParams);
        }

        if (is_string($callable)) {
            if (strpos($callable, '::') !== false) {
                list($class, $method) = explode('::', $callable);
                return $this->invokeClassMethod($class, $method, $namedParams, $classParams);
            } else {
                return $this->invokeFunction($callable, $namedParams, $classParams);
            }
        }

        if (is_array($callable) && count($callable) == 2 && is_string($callable[1])) {
            if (is_object($callable[0])) {
                return $this->invokeObjectMethod($callable[0], $callable[1], $namedParams, $classParams);
            }

            if (is_string($callable[0])) {
                return $this->invokeClassMethod($callable[0], $callable[1], $namedParams, $classParams);
            }
        }

        throw new \InvalidArgumentException("Given argument is not callable.");
    }
public function invoke($callable, array $namedParams = [], array $classParams = [])
    {
        $classParams = $this->reindexclassParams($classParams);

        if ($callable instanceof \Closure) {
            return $this->invokeFunction($callable, $namedParams, $classParams);
        }

        if (is_string($callable)) {
            if (strpos($callable, '::') !== false) {
                list($class, $method) = explode('::', $callable);
                return $this->invokeClassMethod($class, $method, $namedParams, $classParams);
            } else {
                return $this->invokeFunction($callable, $namedParams, $classParams);
            }
        }

        if (is_array($callable) && count($callable) == 2 && is_string($callable[1])) {
            if (is_object($callable[0])) {
                return $this->invokeObjectMethod($callable[0], $callable[1], $namedParams, $classParams);
            }

            if (is_string($callable[0])) {
                return $this->invokeClassMethod($callable[0], $callable[1], $namedParams, $classParams);
            }
        }

        throw new \InvalidArgumentException("Given argument is not callable.");
    }
public function invoke ( $ callable , array $ namedParams = [ ] , array $ classParams = [ ] ) { $ classParams = $ this -> reindexclassParams ( $ classParams ) ; if ( $ callable instanceof \ Closure ) { return $ this -> invokeFunction ( $ callable , $ namedParams , $ classParams ) ; } if ( is_string ( $ callable ) ) { if ( strpos ( $ callable , '::' ) !== false ) { list ( $ class , $ method ) = explode ( '::' , $ callable ) ; return $ this -> invokeClassMethod ( $ class , $ method , $ namedParams , $ classParams ) ; } else { return $ this -> invokeFunction ( $ callable , $ namedParams , $ classParams ) ; } } if ( is_array ( $ callable ) && count ( $ callable ) == 2 && is_string ( $ callable [ 1 ] ) ) { if ( is_object ( $ callable [ 0 ] ) ) { return $ this -> invokeObjectMethod ( $ callable [ 0 ] , $ callable [ 1 ] , $ namedParams , $ classParams ) ; } if ( is_string ( $ callable [ 0 ] ) ) { return $ this -> invokeClassMethod ( $ callable [ 0 ] , $ callable [ 1 ] , $ namedParams , $ classParams ) ; } } throw new \ InvalidArgumentException ( "Given argument is not callable." ) ; }
Invokes a method or anonymous function and returns the result.

Parameter injection is done in two ways:

1. `$classParams` array may contain only objects. For each of the objects
in the array, if the callable function has a parameter with a type hing
to that class, it will be injected.

For example, in the following case $req will be populated by the Request
from `$classParams`:

```
$classParams = [new Request];
$callable = new function(Request $req) { };
$invoker->invoke($callable, [], $classParams);
```

2. `$namedParams` may contain an associative array containing named
parameters. If the callable function has a parameter of the same name as
one of the given parameters, it's value will be injected.

For example:

```
$namedParams = [
'foo' => 1,
'bar' => 2
];
$callable = new function($bar, $foo) { };
$invoker->invoke($callable, $namedParams);
```

In the above example $foo and $bar will be injected from the $namedParams.
Note that the order of parameters in the callback function is not
significant.

If `$namedParams` or `$classParams` contain entries which are not matched
to any parameter of the callback function, they will be ignored.

If the callback function conatins any parameter which is not matched
from `$namedParams` or `$classParams`, it will be set to NULL.

@param  string|callable $callable
@param  array $namedParams Parameters matched by name.
@param  array $classParams Parameters matched by class type hint.

@return mixed The return value of the given callback function.

@throws \InvalidArgumentException when the callable isn't callable
@throws \InvalidArgumentException If `$classParams` contains non-objects.
@throws \InvalidArgumentException If `$classParams` contains multiple
objects of the same class.
Invokes a method or anonymous function and returns the result .