@param AbstractController $controller
@param string $method
@param array $args

@throws \InvalidArgumentException

@return array
968843
private function mapArguments(AbstractController $controller, string $method, array $args) : array
    {
        $return = [];

        $reflection = new \ReflectionClass($controller);
        if (!$reflection->hasMethod($method)) {
            throw new \InvalidArgumentException(sprintf(
                "Method '%s' does not exist on '%s' for route '%s'",
                $method,
                get_class($controller),
                $this->currentRoute->getName()
            ));
        }

        $method = $reflection->getMethod($method);

        foreach ($method->getParameters() as $parameter) {
            if (!isset($args[$parameter->getName()]) && $parameter->isOptional() === false) {
                if ($method->getName() === 'init') {
                    continue;
                }

                throw new \InvalidArgumentException(sprintf(
                    "Missing mandatory arguments on controller definition '%s' on '%s'",
                    $parameter->getName(),
                    get_class($controller)
                ));
            }

            $return[$parameter->getName()] = null;

            if (array_key_exists($parameter->getName(), $args) && $args[$parameter->getName()] !== '') {
                $value = $args[$parameter->getName()];

                if ($parameter->getClass() && $parameter->getClass()->getName() == 'Cawa\Date\DateTime') {
                    $value = new DateTime($value);
                }

                $return[$parameter->getName()] = $value;
            } elseif (!array_key_exists($parameter->getName(), $args)) {
                $return[$parameter->getName()] = $parameter->getDefaultValue();
            }
        }

        return $return;
    }
341598
public function dispatch(Route $route, $controller, $method)
    {
        $parameters = $this->resolveClassMethodDependencies(
            $route->parametersWithoutNulls(), $controller, $method
        );

        if (method_exists($controller, 'callAction')) {
            return $controller->callAction($method, $parameters);
        }

        return call_user_func_array(array($controller, $method), $parameters);
    }
1239523
public function callMethod (&$api, $module, $method, $args = array ())
	{
		
		// Set module class name
		
		$class		= $this->getModuleClass ($module);
		
		// Create module object
		
		$obj		= new $class;
		
		// Set the API reference
		
		$obj->api	= $api;
		
		// Call the method init function for any custom code before the action
		
		if ($obj->callInit ($this, $method, $args))
		{
			
			// Call module method and pass the arguments list as 
			
			$return	= call_user_func_array (array ($obj, $method), array ($args));
			
		}
		
		// Return result
		
		return $obj->getResult ();
		
	}
290113
private function callController(Route $route, array $args)
    {
        $callback = $route->getController();

        $args = array_merge($route->getArgs(), $args);

        // keep route for error
        if (!$this->currentRoute) {
            $this->currentRoute = $route;
            $this->args = $args;
        }

        // simple function
        if (is_callable($callback) && is_object($callback)) {
            return call_user_func_array($callback, [$args]);
        }

        // controller
        preg_match('`([A-Za-z_0-9\\\\<>]+)(?:::)?([A-Za-z_0-9_<>]+)?`', $callback, $find);

        $class = $this->replaceDynamicArgs($find[1], $route, $args);
        $method = isset($find[2]) ? $this->replaceDynamicArgs($find[2], $route, $args) : null;

        // replace class dynamic args
        if (!class_exists($class)) {
            throw new \BadMethodCallException(sprintf(
                "Can't load class '%s' on route '%s'",
                $class,
                $route->getName()
            ));
        }

        $controller = new $class();

        if (is_null($method)) {
            $method = 'get';

            if (self::request()->isAjax() && method_exists($controller, 'ajax')) {
                $method = 'ajax';
            } elseif (self::request()->getMethod() == 'POST' && method_exists($controller, 'post')) {
                $method = 'post';
            }
        }

        $ordererArgs = $this->mapArguments($controller, $method, $args);

        $event = new TimerEvent('router.mainController');
        $event->setData([
            'controller' => $class,
            'method' => $method,
            'data' => $ordererArgs,
        ]);

        try {
            $return = null;
            if (method_exists($controller, 'init')) {
                $return = call_user_func_array(
                    [$controller, 'init'],
                    $this->mapArguments($controller, 'init', $args)
                );
            }

            if (is_null($return)) {
                $return = call_user_func_array([$controller, $method], $ordererArgs);
            }
        } catch (HttpStatusCode $exception) {
            $return = $exception->getResponse();

            if (!$return) {
                $return = self::returnError($exception->getCode());
            }
        }

        self::emit($event);

        return $return;
    }
232928
public function delegate($method, $args = array())
    {
        $options = array(
            'method' => $method,
            'controller' => $this,
        );

        $this->app->applyHook('bono.controller.before', $options, 1);

        // $argCount = count($args);
        // switch ($argCount) {
        //     case 0:
        //         $this->$method();
        //         break;
        //     case 1:
        //         $this->$method($args[0]);
        //         break;
        //     case 2:
        //         $this->$method($args[0], $args[1]);
        //         break;
        //     case 3:
        //         $this->$method($args[0], $args[1], $args[2]);
        //         break;
        //     case 4:
        //         $this->$method($args[0], $args[1], $args[2], $args[3]);
        //         break;
        //     case 5:
        //         $this->$method($args[0], $args[1], $args[2], $args[3], $args[4]);
        //         break;
        //     default:
        try {
            call_user_func_array(array($this, $method), $args);
        } catch(\Exception $e) {
            $this->app->applyHook('bono.controller.after', $options, 20);

            throw $e;
        }

        $this->app->applyHook('bono.controller.after', $options, 20);
    }
99689
public function controller($route, ...$args) {
		// Sanitize the call
		$route = preg_replace('/[^a-zA-Z0-9_\/]/', '', (string)$route);

		// Keep the original trigger
		$trigger = $route;

		// Trigger the pre events
		$result = $this->registry->get('event')->trigger('controller/' . $trigger . '/before', array(&$route, &$args));

		// Make sure its only the last event that returns an output if required.
		if ($result != null && !$result instanceof Exception) {
			$output = $result;
		} else {
			$action = new Action($route);
			$output = $action->execute($this->registry, $args);
		}

		// Trigger the post events
		$result = $this->registry->get('event')->trigger('controller/' . $trigger . '/after', array(&$route, &$args, &$output));

		if ($result && !$result instanceof Exception) {
			$output = $result;
		}

		if (!$output instanceof Exception) {
			return $output;
		}
	}
516593
private static function execController($controller,$action,$args){
        $controller = new $controller();
        $controller->doAction($action,$args);
    }
1319242
public function resolveArguments(Callable $callable, Request $request, Array $route_info)
    {
        $arguments = array();

        // Examine the controller method with reflection and
        // build arguments
        $ref = new \ReflectionMethod($callable[0], $callable[1]);
        $req_attr = $request->query->all();

        foreach ($ref->getParameters() as $parameter) {
            if (array_key_exists($parameter->name, $req_attr)) {
                $arguments[] = $req_attr[$parameter->name];
            } elseif (array_key_exists($parameter->name, $route_info)) {
                $arguments[] = $route_info[$parameter->name];
            } elseif ($parameter->getClass() && $parameter->getClass()->isInstance($request)) {
                $arguments[] = $request;
            } elseif ($parameter->isDefaultValueAvailable()) {
                $arguments[] = $parameter->getDefaultValue();
            } else {
                throw new \RuntimeException(sprintf('Controller %s::%s requires a value for parameter %s.', get_class($callable[0]), $callable[1], $parameter->name));
            }
        }

        return($arguments);
    }
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];
    }
935512
private function exec( $controller_name, $args )
	{
		// Process controller
		$compo = explode( '@', $controller_name );

		if ( count( $compo ) <= 1 ) {

			throw new Exception( sprintf( 'Controller action must be defined in %s.', $controller_name ) );

		}

		// Get controller
		require_once(  $this->controllers_path . $compo[0] . '.php' );
		$classname = sprintf( $this->namespace . '\Controllers\%s', $compo[0]);
		$controller = new $classname( $this->view );

		if ( !method_exists( $controller, $compo[1] ) ) {

			throw new Exception( sprintf( 'Controller action "%s" not found in %s.', $compo[1], $compo[0] ) );

		}

		return call_user_func_array( [ $controller, $compo[1] ], $args );
	}
606399
protected function getMappedOperator($method, ArgumentBag $args)
    {
        if ($not = $args->get('not')) {
            $args->set('not', false);
        }

        if ($null = $this->isWhereNull($method, $args)) {
            $args->set('not', true);
        }

        return ($not ^ $null) ? '<' : '>=';
    }
492758
public function defaultRoute($controller, $action = null, array $args = [])
    {
        $this->_defaultRoute = [
            'route' => implode('/', [$this->module->id, $controller, (empty($action)) ? 'index' : $action]),
            'args' => $args,
            'originalArgs' => $args,
        ];
    }
842851
public function createUrl($controller, array $args = array(), $index = 0)
    {
        $collection = $this->mapManager->findUriTemplatesByController($controller);

        if (!empty($collection)) {
            if (isset($collection[$index])) {
                return $this->createVariadicUrl($collection[$index], $args);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
170756
public function callController($arguments)
    {
        $params = [];
        /*
        | Check if whether user trying to access module
        | If module we will setup module configuration
        | or else setup default MVC configurations
         */
        if (string_has($arguments[0], '::')) {
            $exp = string_split($arguments[0], '::');
            $this->setModuleConfiguration($exp);
        } else {
            $this->setUpControllerAndMethodName($arguments);
        }

        if (isset($arguments[1])) {
            $params = $arguments[1];
        }

        $args = (!is_array($params)) ? [$params] : $params;

        /*
        | Get the instance of controller from Cygnite Container
        | and inject all dependencies into controller dynamically.
        | It's cool! You can write powerful rest api using restful
        | routing
         */
        return $this->handleControllerDependencies($this->controllerWithNS, $this->method, $args);
    }
1101137
public function callMethod($resourceNamePlural, $methodName, $arguments = [])
    {
        $controller = $this->createController($resourceNamePlural);

        if (method_exists($controller, $methodName) == false) {
            throw new InvalidMethodException('The method ('.$methodName.') does not exist for the class '.get_class($controller));
        }
        return call_user_func_array([$controller, $methodName], $arguments);
    }
599529
public function dispatch($route, $controller, $method)
    {
        if (method_exists($controller, $method)) {
            return $this->container->call(
                [$controller, $method],
                $this->getMethodArguments($route)
            );
        }

        return $controller->missingMethod($method);
    }
854369
private void registerControllerMethods(Map<Method, Class<? extends Annotation>> controllerMethods, Controller controller) {
        List<Route> controllerRoutes = createControllerRoutes(controllerMethods);
        for (Route controllerRoute : controllerRoutes) {
            if (controller != null) {
                ((ControllerHandler) controllerRoute.getRouteHandler()).setController(controller);
                controllerRoute.bind("__controller", controller);
            }
        }

        this.routes.addAll(controllerRoutes);
    }