Maps a called controller action to a component method

@return bool|\Cake\Http\Response
179632
public function mapAction() {
		$action = $this->_getRequest()->params['action'];
		if ($this->getConfig('directMapping') === true) {
			$this->_directMapping($action);
		}

		return $this->_mapAction($action);
	}
684848
public function renderPartial()
    {
        $this->controller->setComponentContext($this);
        $result = call_user_func_array([$this->controller, 'renderPartial'], func_get_args());
        $this->controller->setComponentContext(null);
        return $result;
    }
959502
public function setAction()
    {
        // Constructs the current action method
        $this->action = strtolower($this->action) . 'Action';

        // Checks if the current action method exists in the current controller
        if (!method_exists($this->controller, $this->action)) {

            // Attributes the default action method to the current action method
            $this->action = self::DEFAULT_ACTION;
        }
    }
745901
protected function action()
    {
        if ($this->argument('action') != null) {
            return $this->argument('action');
        }
        if (strtolower($this->option('type')) != 'regular') {
            return $this->argument('link') . 'Controller';
        }
        return $this->argument('link');
    }
923684
private function mapsController($controller, $uriapp = NULL, $method = NULL, $parentController = NULL){
        $httpMethod= isset($controller['httpMethod']) ? $controller['httpMethod'] : '*';
        if($parentController != NULL){
            $controller['url']= rtrim($parentController['url'], '/') . '/' . ltrim($controller['url'], '/');
        }
        $maps= UrlUri::mapsActualUrl($controller['url'], $uriapp) && UrlUri::mapsActualMethod($httpMethod, $method);
        if($maps){
            $mapController= array(
                'url' => $controller['url'],
                'httpMethod' => $httpMethod,
                'location' => isset($controller['location']) ? $controller['location'] : NULL,
                'namespace' => isset($controller['namespace']) ? $controller['namespace'] : NULL,
                'class' => isset($controller['class']) ? $controller['class'] : $parentController['class'],
                'method' => isset($controller['method']) ? $controller['method'] : NULL,
                'properties' => isset($controller['properties']) ? $controller['properties'] : array(),
                'middlewares' => isset($controller['middlewares']) ? $controller['middlewares'] : []
            );
            if($parentController != NULL){
                if(! isset($controller['class'])){
                    $mapController['location']= isset($parentController['location']) ? $parentController['location'] : NULL;
                    $mapController['namespace']= isset($parentController['namespace']) ? $parentController['namespace'] : NULL;
                }
                if(isset($parentController['properties'])){
                    $mapController['properties']= array_merge($parentController['properties'], $mapController['properties']);
                }
                if(isset($parentController['middlewares'])){
                    $mapController['middlewares'] = array_merge($parentController['middlewares'], $mapController['middlewares']);
                }
            }
            
            return $mapController;
        }else{
            return NULL;
        }
    }
1159338
public function dispatch()
    {
		/**
         * Calling before dispatch listener
         */
		if ( is_object($this->_events_manager) )
        {
            $this->_events_manager->fire( "dispatch:beforeDispatch", $this );
		}

		$finished = false;

		$number_dispatches = 0;

		while ( !$finished )
		{
			$number_dispatches++;

			if ( $number_dispatches == 100 )
            {
                $this->_throwDispatchException( "Dispatch error. Cyclic routing.", self::EXCEPTION_CYCLIC_ROUTING );
				break;
			}

            $controller_name = $this->_route->getControllerName();
            $action_name     = $this->_route->getActionName();
            $params          = $this->_route->getParams();

            if ( !class_exists($controller_name) )
            {
                if ( $this->_throwDispatchException( $controller_name . " controller class cannot be loaded.", self::EXCEPTION_CONTROLLER_NOT_FOUND ) == false )
                {
                    continue;
                }

                break;
            }

            $controller_instance = new $controller_name();

            if ( !method_exists($controller_instance, $action_name) )
            {
                if ( $this->_throwDispatchException( $action_name . "Action action does not exist in " . $controller_name . ".", self::EXCEPTION_ACTION_NOT_FOUND ) == false )
                {
                    continue;
                }

                break;
            }

            /**
             * Calling before execute route listener
             */
            if ( is_object($this->_events_manager) )
            {
                $this->_events_manager->fire( "dispatch:beforeExecuteRoute", $this );

                /**
                 * If there was a forward in the listener
                 */
                if ( $this->_was_forwarded )
                {
                    $this->_was_forwarded = false;
                    continue;
                }
            }

            $controller_instance->setDI( $this->_di );

            $controller_instance->initialize();

			/**
             * Calling action in controller with params
             */
            call_user_func_array( array($controller_instance, $action_name), $params );

			/**
             * If there was a forward in the action
             */
			if ( $this->_was_forwarded )
            {
				$this->_was_forwarded = false;
				continue;
			}

			$finished = true;
		}
    }
948103
protected function _getControllerActions()
    {
        $table = $entity = [];

        $actions = $this->_getAllowedActions();
        foreach ($actions as $actionName => $config) {
            list($scope, $actionConfig) = $this->_getControllerActionConfiguration($actionName, $config);
            ${$scope}[$actionName] = $actionConfig;
        }

        $actionBlacklist = [];
        $groups = $this->_action()->getConfig('scaffold.action_groups') ?: [];
        foreach ($groups as $group) {
            $group = Hash::normalize($group);
            foreach ($group as $actionName => $config) {
                if (isset($table[$actionName]) || isset($entity[$actionName])) {
                    continue;
                }
                if ($config === null) {
                    $config = [];
                }
                list($scope, $actionConfig) = $this->_getControllerActionConfiguration($actionName, $config);
                $realAction = Hash::get($actionConfig, 'url.action', $actionName);
                if (!isset(${$scope}[$realAction])) {
                    continue;
                }

                $actionBlacklist[] = $realAction;
                ${$scope}[$actionName] = $actionConfig;
            }
        }

        foreach ($actionBlacklist as $actionName) {
            unset($table[$actionName]);
            unset($entity[$actionName]);
        }

        return compact('table', 'entity');
    }
1352473
public function getAction($matches = [])
    {
        if (!isset($this->route['controller'])) {
            return false;
        }
        $controller = $this->route['controller'];
        preg_match("/@(.*)/", $controller, $matches);
        if (!isset($matches[1])) {
            throw new RuntimeException('Unable to resolve action name from controller.');
        }
        return $matches[1];
    }
490212
public function indexAction()
    {
        $service = $this->getLayoutService();
        try {
            $theme = $service->getTheme(
                $this->params()->fromRoute('theme')
            );
        } catch (RuntimeException $e) {
            $this->flashMessenger()->addMessage($e->getMessage());
            return $this->redirect()
                ->toRoute('sc-admin/layout')
                ->setStatusCode(303);
        }

        $event = $this->getRequest()->getPost('suboperation');
        if (! empty($event)) {
            $events = $this->getEventManager();
            $params = $this->request->getPost();
            $params['theme'] = $theme->getName();
            $results = $events->trigger($event, $this, $params);
            foreach ($results as $result) {
                if ($result instanceof Response) {
                    return $result;
                }
            }
        }

        $view = new ViewModel([
            'controlSet' => $service->getControlSet(),
            'regions' => $service->getRegions($theme->getName()),
            'theme' => $theme,
        ]);

        $flashMessenger = $this->flashMessenger();
        if ($flashMessenger->hasMessages()) {
            $view->messages = $flashMessenger->getMessages();
        }

        return $view;
    }
520568
public function dispatch()
    {
        $handler = [$this->controller, 'initialize'];
        if (method_exists($this->controller, 'initialize') && is_callable($handler)) {
            call_user_func($handler);
        }

        $this->isCallableOrException();

        return call_user_func_array([$this->controller, $this->action], $this->params);
    }
807951
public function Link($action = null)
    {
        if ($this->shortcodableclass) {
            return Controller::join_links(
                $this->config()->url_base,
                $this->config()->sc_url_segment,
                'edit',
                $this->shortcodableclass
            );
        }
        return Controller::join_links($this->config()->url_base, $this->config()->sc_url_segment, $action);
    }
828125
public function Link($action = null)
    {
        if ($this->hasParentPage()) {
            return Controller::join_links(
                $this->hasParentPage()->Link(),
                $this->hasViewAction(),
                $this->owner->RelativeLink($action)
            );
        }

        return false;
    }
178408
public function getActionMap()
    {
        $plugins = $this->getLoadedPluginPaths();

        $actionMap = [];
        foreach ($plugins as $plugin => $path) {
            $controllers = $this->getControllersForPlugin($plugin, $path);
            foreach ($controllers as $controller) {
                $actions = $this->introspectController($controller['path']);
                if (empty($actions)) {
                    continue;
                }
                foreach ($actions as $action) {
                    $path = "{$plugin}.{$controller['name']}.{$action}";
                    if (in_array($path, $this->_guestActions)) {
                        continue;
                    }
                    $actionMap[$path] = [
                        'plugin' => $plugin,
                        'controller' => $controller['name'],
                        'action' => $action
                    ];
                }
            }
        }

        $appControllers = $this->getControllersForApp();
        foreach ($appControllers as $controller) {
            $actions = $this->introspectController($controller['path']);

            if (empty($actions)) {
                continue;
            }
            foreach ($actions as $action) {
                if (strpos($controller['path'], ROOT . DS . 'src' . DS . 'Controller') === false) {
                    $path = "App.{$controller['name']}.{$action}";
                    if (in_array($path, $this->_guestActions)) {
                        continue;
                    }
                    $actionMap[$path] = [
                        'plugin' => 'App',
                        'controller' => $controller['name'],
                        'action' => $action
                    ];
                } else {
                    $namespaceParts = explode(DS, substr($controller['path'], strlen(ROOT . DS . 'src' . DS . 'Controller') + 1));
                    array_pop($namespaceParts);
                    $namespace = join('/', $namespaceParts);
                    if (!empty($namespace)) {
                        $path = "App.{$namespace}/{$controller['name']}.{$action}";
                    } else {
                        $path = "App.{$controller['name']}.{$action}";
                    }
                    if (in_array($path, $this->_guestActions)) {
                        continue;
                    }
                    $actionMap[$path] = [
                        'plugin' => 'App',
                        'controller' => !empty($namespace) ? $namespace . '/' . $controller['name'] : $controller['name'],
                        'action' => $action
                    ];
                }
            }
        }

        return $actionMap;
    }
249841
public function httpResponse()
    {
        // get the template
        $template = $this->view()->getTemplate();

        // if there is no template, then we return false
        if(empty($template)) {
            return false;
        }

        // get view data
        $viewData = $this->view()->getAssignedData();

        // assign application data to view
        $viewData['App'] = [
            'Config'       => $this->getEnvironmentConfig(),
            'Components'   => $this->environment->getComponentConfigs()->toArray(),
            'Environment'  => $this->getEnvironmentName(),
            'AbsolutePath' => $this->getAbsolutePath(),
            'WebPath'      => $this->getWebPath()
        ];

        // render the view and assign it to the response object
        return new Response($this->getTemplateEngineInstance()->fetch($this->view()->getTemplate(), $viewData));
    }
566489
public function map() {
		$modules = Module::all();
		
		//dd($modules);
		
		foreach ($modules as $module) {
			$routes = $module->routes;
			$routesFolder = 'routes'.DIRECTORY_SEPARATOR;
			
			if ($routes) {
				foreach ($routes as $route) {
					if (strrpos($route, $routesFolder."web")) {
						
						$this->mapWebRoute($route, $module->namespace);
					}
					elseif (strrpos($route, $routesFolder."api")) {
						
						$this->mapApiRoute($route, $module->namespace);
					}
				}
			}
		}
	}
1241002
public function main()
    {
        if (count($this->args) < 2) {
            return $this->error('Please pass the controller and action name.');
        }
        $controllerName = Inflector::camelize($this->args[0]);
        $actionName = Inflector::camelize($this->args[1]);
        $this->plugin = isset($this->params['plugin']) ? $this->params['plugin'] : null;

        $this->BakeTemplate->set('controllerName', $controllerName);
        $this->BakeTemplate->set('actionName', $actionName);
        $content = $this->BakeTemplate->generate('FrontendBridge.webroot/js_controller');

        $this->bake($controllerName, $actionName, $content);
    }
1336628
private function controller()
    {
        $controllerName = Router::getController();
        $actionName = Router::getAction();
        $controllerNamespace = Configuration::read('mvc.controller.namespace');
        $controllerNamespace = $controllerNamespace . '\\' . $controllerName;
        if (!class_exists($controllerNamespace)) {
            throw new \Exception('Controller "' . $controllerNamespace . '" doesn\' exist.');
            return false;
        }
        $controller = new $controllerNamespace();
        if (!method_exists($controllerNamespace, 'render')) {
            $errorMessage = 'render() method isn\'t available in Controller "' . $controllerNamespace . '".<br />';
            $errorMessage .= 'Your controller may not extends \Pabana\Mvc\Controller.';
            throw new \Exception($errorMessage);
            return false;
        }
        $bodyContent = $controller->render($actionName);
        return $bodyContent;
    }