Bind the matched parameters from the request with the callable parameters.

@param callable $controller the callable to be executed
@param array    $matched    the parameters extracted from the uri

@return array The
543275
protected function bindParameters(callable $controller, array $matched): array
    {
        if (is_array($controller)) {
            $reflector = new \ReflectionMethod($controller[0], $controller[1]);
            $controllerName = sprintf('%s::%s()', get_class($controller[0]), $controller[1]);
        } elseif (is_object($controller) && ! $controller instanceof \Closure) {
            $reflector = (new \ReflectionObject($controller))->getMethod('__invoke');
            $controllerName = get_class($controller);
        } else {
            $controllerName = ($controller instanceof \Closure) ? get_class($controller) : $controller;
            $reflector = new \ReflectionFunction($controller);
        }

        $parameters = $reflector->getParameters();

        $bindParams = [];
        foreach ($parameters as $param) {
            // @notice \ReflectionType::getName() is not supported in PHP 7.0, that is why we use __toString()
            $paramType = $param->hasType() ? $param->getType()->__toString() : '';
            $paramClass = $param->getClass();

            if (array_key_exists($param->getName(), $matched)) {
                $bindParams[] = $this->transformToScalar($matched[$param->getName()], $paramType);
            } elseif ($paramClass && array_key_exists($paramClass->getName(), $matched)) {
                $bindParams[] = $matched[$paramClass->getName()];
            } elseif ($param->isDefaultValueAvailable()) {
                $bindParams[] = $param->getDefaultValue();
            //} elseif ($param->hasType() && $param->allowsNull()) {
            //    $result[] = null;
            } else {
                // can't find the value, or the default value for the parameter => throw an error
                throw new InvalidArgumentException(sprintf(
                    'Controller "%s" requires that you provide a value for the "$%s" argument (because there is no default value or because there is a non optional argument after this one).',
                    $controllerName,
                    $param->getName()
                ));
            }
        }

        return $bindParams;
    }
983108
public function filter(callable $filter, callable $controller)
    {
        $pattern = $this->getFrontController()->addController(':all', $controller)->getPattern();
        $pattern->addFilter($filter);
        return new IRoutePatternSetterAdapter($pattern);
    }
163800
public function matchRoute(Request $request)
    {
        $attributes = [];
        $route = $this->getRouteByPath($request->getPathInfo(), (new RequestContext())->fromRequest($request), $attributes);
        $request->attributes->add($attributes);
        $request->attributes->set('_route', $route);

        return new MatchedRoute($route, $attributes);
    }
95120
protected function bindToController($request, $url, $controller)
    {
        $array  = explode('|', $url, 2);
        $action = !empty($array[0]) ? $array[0] : $this->router->config('default_action');
        $param  = [];

        if (!empty($array[1])) {
            $this->parseUrlParams($request, $array[1], $param);
        }

        return new ControllerDispatch($request, $this, $controller . '/' . $action, $param);
    }
385142
public function makeSoftDeletesCondition($controller)
    {
        if (!$controller->withTrashed()) return [];
        return [
            'deleted_at' => [
                'type' => 'select',
                'label' => 'status',
                'options' => [
                    'exists' => 'exists',
                    'deleted' => 'deleted'
                ],
                'query' => function($query, $condition, $input) {

                    // If not deleted...
                    if (($input == 'exists' && $condition == '=') ||
                        ($input == 'deleted' && $condition == '!=')) {
                        $query->whereNull('deleted_at');

                    // If deleted...
                    } else if (($input == 'deleted' && $condition == '=') ||
                        ($input == 'exists' && $condition == '!=')) {
                        $query->whereNotNull('deleted_at');
                    }
                },
            ]
        ];
    }
381681
protected function prepareCallController($controller, $newRequest)
    {
        $controller = parent::prepareCallController($controller, $newRequest);
        $controller->setView($this->getView());

        return $controller;
    }
549219
private function detectClassAndMethod(string $controller): ?array
    {
        if (preg_match('#(.+)::([\w]+)#', $controller, $matches)) {
            $class = $matches[1];
            $method = $matches[2];
        } elseif (class_exists($controller)) {
            $class = $controller;
            $method = '__invoke';
        } else {
            if (preg_match('#(.+):([\w]+)#', $controller, $matches)) {
                $controller = $matches[1];
                $method = $matches[2];
            }

            if ($this->container->has($controller)) {
                $class = get_class($this->container->get($controller));

                if (!isset($method) && method_exists($class, '__invoke')) {
                    $method = '__invoke';
                }
            }
        }

        if (!isset($class) || !isset($method)) {
            return null;
        }

        return [$class, $method];
    }
121881
public function getRoutesParameters($method, $controller, $reflection, $replace = 'Controller'): array
    {
        $actionName = str_replace('Action', '', $method);
        $routeArr = $this->getActionName($actionName);

        $verb = isset($routeArr[0]) && in_array($routeArr[0], $this->verbs) ? $routeArr[0] : 'get';
        /*
        | For deleteAction HTTP verb name act as method name
         */
        $action = isset($routeArr[1]) ? $actionName : $verb . ucfirst($verb);

        $prefix = str_replace($replace, '', Inflector::getClassNameFromNamespace($controller));

        $plain = $this->getPlainUri($action, Inflector::controllerPath($prefix));
        $uri = $this->addUriWildcards($plain, $reflection, $method);

        return [$uri, $verb, $method, $plain];
    }
628935
public function parameters($request)
    {
        // If the route has a regular expression for the host part of the URI, we will
        // compile that and get the parameter matches for this domain. We will then
        // merge them into this parameters array so that this array is completed.
        $parameters = $this->bindPathParameters($request);

        // If the route has a regular expression for the host part of the URI, we will
        // compile that and get the parameter matches for this domain. We will then
        // merge them into this parameters array so that this array is completed.
        if (! is_null($this->route->compiled->getHostRegex())) {
            $parameters = $this->bindHostParameters(
                $request, $parameters
            );
        }

        return $this->replaceDefaults($parameters);
    }
166099
public function create(array $parameters, $controller = null) {
        $parameters = $this->parseParameters($parameters, $controller);

        $action = new Action(
            $parameters['name'],
            $parameters['pattern'],
            $parameters['uses'],
            $parameters['group']
        );

        $this->setProperties($action, $parameters);

        return $action;
    }
167291
public function dispatchAction($controller)
    {
        $action = $this->matchRoute[key($this->matchRoute)]['action'] . 'Action';

        $viewModel = $controller->$action();

        if ($viewModel instanceof ViewModel) {
            $this->view->setVariables($viewModel->getVariables());
        }
    }
980186
protected function getControllerMiddlewareFromInstance($controller, $method)
    {
        $middlewares = $this->router->getMiddleware();

        //
        $results = array();

        foreach ($controller->getMiddleware() as $middleware => $options) {
            if (ControllerDispatcher::methodExcludedByOptions($method, $options)) {
                continue;
            }

            list($name, $parameters) = array_pad(explode(':', $middleware, 2), 2, null);

            $middleware = Arr::get($middlewares, $name, $name);

            $results[] = (! $middleware instanceof Closure) ? $middleware : $name;
        }

        return $results;
    }
1090774
protected function bindHostParameters($request, $parameters)
    {
        preg_match($this->route->compiled->getHostRegex(), $request->getHost(), $matches);

        return array_merge($this->matchToKeys(array_slice($matches, 1)), $parameters);
    }
1322558
private function parseCallableController($controller, $container)
    {
        $controller  = rtrim($this->namespace, "\\") . "\\" . $this->parseCallablePlaceholders($controller);

        if ($container === null) {
               return new $controller;
        } else return $container($controller);
    }
1237165
private function executeController($controller, Route $method, $matches) {

		if(false === is_object($controller)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type object, "%s" given', __METHOD__, gettype($controller)), E_USER_ERROR);
		}

		if(false === is_array($matches)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($matches)), E_USER_ERROR);
		}

		//Load the module dispatch file if exists and readable
		$this -> loadBoot($method -> getModule());

		//Execute start method if controller supports it
		if(true === is_callable([$controller, '__start'])) {
			call_user_func_array([$controller, '__start'], []);
		}

		//Execute main function
		$action = Application :: get(['prefix', 'action']) . $method -> getAction();

		//Trigger error if main function does not exists
		if(false === is_callable([$controller, $action])) {
			return trigger_error(sprintf('Method "%s" does not exists in "%s" controller', Application :: get(['prefix', 'action']) . ucfirst($method -> getAction()), $method -> getController()), E_USER_ERROR);
		}

		call_user_func_array([$controller, $action], $matches);

		//Execute end method if controller supports it
		if(true === is_callable([$controller, '__end'])) {
			call_user_func_array([$controller, '__end'], []);
		}
	}
714174
public function execute($matches) {
		if (is_string($this->callable)) { // If the callable is a string, call the action of controller
			$params = explode('#', $this->callable);

            if (count($params) == 2) {
                $controllerPrefix = $params[0];
                $controllerPrefix = str_replace(':', '\\', $controllerPrefix);

    			$controller = $controllerPrefix."Controller";

    			$controller = new $controller();
    			$action = $params[1].'Action';

    			return call_user_func_array(array($controller, $action), $matches);


    			return $controller->$action();

            } else {
                throw new RouterException('Invalid controller name '.$this->callable);
            }

		} else { // If the callable is a function, execute the function
			return call_user_func_array($this->callable, $matches);
		}
	}
1372527
public function call(callable $callback, array $matched)
    {
        $parameters = $this->bindParameters($callback, $matched);

        return call_user_func_array($callback, $parameters);
    }