public static function functionDI(\Closure $function,
                                      \Closure $callback = null)
    {
        $reflection     = new \ReflectionFunction($function);
        $functionParams = $reflection->getParameters();
        $inputParams    = [];
        if ($callback !== null) {
            foreach ($functionParams as $functionParam) {
                $param = $callback($functionParam->name);
                if (!empty($param)) {
                    $inputParams[] = $param;
                }
            }
        }
        return call_user_func_array($function, $inputParams);
    }
public static function functionDI(\Closure $function,
                                      \Closure $callback = null)
    {
        $reflection     = new \ReflectionFunction($function);
        $functionParams = $reflection->getParameters();
        $inputParams    = [];
        if ($callback !== null) {
            foreach ($functionParams as $functionParam) {
                $param = $callback($functionParam->name);
                if (!empty($param)) {
                    $inputParams[] = $param;
                }
            }
        }
        return call_user_func_array($function, $inputParams);
    }
public static function functionDI ( \ Closure $ function , \ Closure $ callback = null ) { $ reflection = new \ ReflectionFunction ( $ function ) ; $ functionParams = $ reflection -> getParameters ( ) ; $ inputParams = [ ] ; if ( $ callback !== null ) { foreach ( $ functionParams as $ functionParam ) { $ param = $ callback ( $ functionParam -> name ) ; if ( ! empty ( $ param ) ) { $ inputParams [ ] = $ param ; } } } return call_user_func_array ( $ function , $ inputParams ) ; }
Call closure with dependency injection

@param \Closure $function
@param \Closure $callback
@return mixed
Call closure with dependency injection