@param string $controllerName

@return array
18837
protected function _getUsedComponents($controllerName) {
		$plugin = $controllerName !== 'AppController' ? $this->getConfig(static::CONFIG_PLUGIN) : null;
		$className = App::className(($plugin ? $plugin . '.' : '') . $controllerName, 'Controller');
		if (!$className) {
			return [];
		}

		/** @var \App\Controller\AppController $controller */
		$controller = new $className();

		$components = [];
		foreach ($controller->components()->loaded() as $component) {
			$components[$component] = get_class($controller->components()->get($component));
		}

		if ($controllerName === 'AppController') {
			return $components;
		}

		$appControllerComponents = $this->_getUsedComponents('AppController');
		$components = array_diff_key($components, $appControllerComponents);

		return $components;
	}
864672
private function getControllerParams(Request $request, $controllerString)
    {
        $query = $request->query->all();
        $methodParameters = $this->getControllerParameters($controllerString);

        $parameters = array();
        foreach ($methodParameters as $methodParameter) {
            $parameterName = $methodParameter->getName();
            if ('request' === $parameterName) continue;

            if (isset($query[$parameterName])) {
                $parameters[$parameterName] = $query[$parameterName];
                unset($query[$parameterName]);
            }
        }

        return array($parameters, $query);
    }
716490
protected function parseController($controller)
    {
        if (!is_array($controller) || !is_object($controller[0]) || !isset($controller[1])) {
            return null;
        }

        if (!preg_match('#Controller\\\(.+)Controller$#', get_class($controller[0]), $matches)) {
            return null;
        }

        return ['name' => $matches[1], 'action' => $controller[1]];
    }
722532
protected function _getArgumentNames($controller, $command)
    {
        $controllerClassName = $this->_getControllerClassName($controller);
        if (!class_exists($controllerClassName)) {
            return [];
        }

        $command = Text::camelize($command) . 'Command';
        if (!method_exists($controllerClassName, $command)) {
            return [];
        }

        $arguments = [];
        foreach ((new \ReflectionMethod($controllerClassName, $command))->getParameters() as $parameter) {
            $arguments[] = '--' . strtr($parameter->name, '_', '-');
        }

        return $arguments;
    }
1242960
private function getPartsFromControllerName($controller)
    {
        if (3 != count($parts = explode(':', $controller))) {
            throw new \InvalidArgumentException(sprintf('The "%s" controller is not a valid a:b:c controller string.', $controller));
        }

        list($moduleName, $controller, $action) = $parts;
        $controller = str_replace('/', '\\', $controller);
        $module     = $this->moduleManager->getModule($moduleName);

        if (!is_object($module)) {
            throw new \RuntimeException(sprintf(
                'Unable to locate module: %s, when parsing controller: %s',
                $moduleName, $controller
            ));
        }

        $moduleName = $module->getName();

        return [$module, $moduleName, $controller, $action];
    }
1318404
public static function getControllerAccess($controllerClassName)
    {
        try{
            $returnValue = self::getCacheImplementation()->get(self::SERIAL_PREFIX_MODULE.$controllerClassName);
        } catch (\common_cache_Exception $e) {
            
            $extId = MapHelper::getExtensionFromController($controllerClassName);
            $extension = MapHelper::getUriForExtension($extId);
            $module = MapHelper::getUriForController($controllerClassName);
            
            $roleClass = new \core_kernel_classes_Class(GenerisRdf::CLASS_ROLE);
            $accessProperty = new \core_kernel_classes_Property(AccessService::PROPERTY_ACL_GRANTACCESS);

            $returnValue = array('module' => array(), 'actions' => array());
            
            // roles by extensions
            $roles = $roleClass->searchInstances(array(
                    $accessProperty->getUri() => $extension
                ), array(
                    'recursive' => true, 'like' => false
            ));
            foreach ($roles as $grantedRole) {
                $returnValue['module'][] = $grantedRole->getUri();
            }
            
            // roles by controller
            $filters = array(
                $accessProperty->getUri() => $module
            );
            $options = array('recursive' => true, 'like' => false);
            
            foreach ($roleClass->searchInstances($filters, $options) as $grantedRole){
                $returnValue['module'][] = $grantedRole->getUri();
            }
            
            // roles by action
            foreach (ControllerHelper::getActions($controllerClassName) as $actionName) {
                $actionUri = MapHelper::getUriForAction($controllerClassName, $actionName);
                $rolesForAction = $roleClass->searchInstances(array(
                    $accessProperty->getUri() => $actionUri
                ), array('recursive' => true, 'like' => false));
                if (!empty($rolesForAction)) {
                    $actionName = MapHelper::getActionFromUri($actionUri);
                    $returnValue['actions'][$actionName] = array();
                    foreach ($rolesForAction as $roleResource) {
                        $returnValue['actions'][$actionName][] = $roleResource->getUri();
                    }
                }
            }
            
            self::getCacheImplementation()->put($returnValue, self::SERIAL_PREFIX_MODULE.$controllerClassName);
        }
        return $returnValue;
    }
202531
public static function getCapabilities(string $controllerName = null, array $actions = []): array
    {
        $result = [];

        if (empty($controllerName)) {
            return $result;
        }

        $skipControllers = Configure::read('RolesCapabilities.accessCheck.skipControllers');
        if (is_callable([$controllerName, 'getSkipControllers'])) {
            $skipControllers = array_merge($skipControllers, $controllerName::getSkipControllers());
        }

        if (in_array($controllerName, $skipControllers)) {
            return $result;
        }

        $actions = static::getActions($controllerName, $actions);

        if (empty($actions)) {
            return $result;
        }

        // get controller table instance
        $table = static::getControllerTableInstance($controllerName);

        $result = static::getCapabilitiesForAction($table, $controllerName, $actions);

        return $result;
    }
150065
public function getMessagesFor(string $fieldName) : array
    {
        $invalidInputException = $this->getInvalidInputExceptionFor($fieldName);

        if ($invalidInputException) {
            return $invalidInputException->getMessages();
        }

        $invalidFormSubmission = $this->getInnerFormSubmissionExceptionFor($fieldName);

        if ($invalidFormSubmission) {
            return $invalidFormSubmission->getFieldMessageMap();
        }

        return [];
    }
477096
protected static function _controllerMethods($className)
    {
        if (!class_exists($className)) {
            return [];
        }

        $methods = (array)get_this_class_methods($className);
        $actions = [];
        foreach ($methods as $methodName) {
            try {
                $method = new ReflectionMethod($className, $methodName);
                if ($method->isPublic()) {
                    $actions[] = $methodName;
                }
            } catch (\ReflectionException $e) {
                // error
            }
        }

        return $actions;
    }
347631
protected function controller($controllername)
    {
        if (str_contains($controllername, '/')) {
            $controllername = str_replace('/', '\\', $controllername);
        }

        if (str_contains($controllername, '@')) {
            return ucfirst($controllername);
        }
        return ucfirst($controllername . '@index');
    }
395140
public function serializePayload(ControllerContext $controllerContext)
    {
        return [
            'contextPath' => $this->getNode()->getContextPath(),
            'parentContextPath' => $this->getNode()->getParent()->getContextPath()
        ];
    }
951363
public function getAppControllersMethod($methodName, $scope = '')
    {
        $methods = [];
        
        if ($this->appControllerRefls) {
            foreach ($this->appControllerRefls as $appRefl) {
                if ($appRefl->hasMethod($methodName)) {
                    $method = $appRefl->getMethod($methodName);
                    
                    if ($this->isApplicationController($method->getDeclaringClass()->getName())) {
                        if ($scope) {
                            $isScope = 'is' . ucfirst($scope);
                            if (!$method->$isScope()) {
                                continue;
                            }
                        }
                        $methods[] = $method->getClosure($this);
                    }
                }
            }
        }
        
        return $methods;
    }
582108
public function generate($controllerName, $action)
    {
        $this->route = new CallbackRoute();
        $this->route->addPossibilities(array($controllerName, $action));
        return array($this, "run");
    }
300254
private function isControllerClassNameValid($controllerClassName)
    {
        $returnValue = true;

        if (!class_exists($controllerClassName)) {
            common_Logger::w($controllerClassName.' not found');
            $returnValue = false;
        } elseif (!is_subclass_of($controllerClassName, 'Module') && !is_subclass_of($controllerClassName, Controller::class)) {
            common_Logger::w($controllerClassName.' is not a valid Controller.');
            $returnValue = false;
        } else {
            // abstract so just move along
            $reflection = new \ReflectionClass($controllerClassName);
            if ($reflection->isAbstract()) {
                common_Logger::i($controllerClassName.' is abstract');
                $returnValue = false;
            }
        }

        return $returnValue;
    }
4118
public function getActions($controller)
    {
        $actions = [];
        foreach (get_class_methods($controller) as $method) {
            if (preg_match('#^(.*)Action$#', $method, $match)) {
                $actions[] = $match[1];
            }
        }

        return $actions;
    }
1304169
protected function _getCommands($controller)
    {
        $commands = [];
        try {
            $controllerClassName = $this->_getControllerClassName($controller);

            if (!class_exists($controllerClassName)) {
                return [];
            }

            foreach ((new \ReflectionClass($controllerClassName))->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                if (!$method->isStatic() && $method->isPublic() && preg_match('#^(.*)Command$#', $method->getShortName(), $matches) === 1) {
                    $commands[] = Text::underscore($matches[1]);
                }
            }
        } catch (\Exception $e) {

        }

        return $commands;
    }
716369
private function getControllerParameters($controllerString)
    {
        $controllerInfo = explode(':', $controllerString);

        if (count($controllerInfo) !== 3) {
            throw new AjaxBlocksException(
                "$controllerString is not a correct controller name.",
                AjaxBlocksErrorCodes::WRONG_CONTROLLER_NAME
            );
        }

        try {
            /** @var Bundle $bundle */
            $bundle = $this->get('kernel')->getBundle($controllerInfo[0]);
        } catch (\Exception $ex) {
            throw new AjaxBlocksException(
                "Bundle \"$controllerInfo[0]\" does not exist or is not loaded.",
                AjaxBlocksErrorCodes::BUNDLE_DOES_NOT_EXIST
            );
        }

        $namespace = $bundle->getNamespace();
        $controllerName = $controllerInfo[1].'Controller';
        $controllerMethod = $controllerInfo[2].'Action';
        $className = $namespace.'\\Controller\\'.$controllerName;

        if (!class_exists($className)) {
            throw new AjaxBlocksException(
                "Class \"$className\" does not exist.",
                AjaxBlocksErrorCodes::CONTROLLER_CLASS_DOES_NOT_EXISTS
            );
        }

        $reflectionClass = new \ReflectionClass($className);

        if (!$reflectionClass->hasMethod($controllerMethod)) {
            throw new AjaxBlocksException(
                "Class \"$className\" does not have a method called \"$controllerMethod\".",
                AjaxBlocksErrorCodes::CONTROLLER_CLASS_METHOD_DOES_NOT_EXISTS
            );
        }

        $controller = $reflectionClass->getMethod($controllerMethod);
        if (!$controller->isPublic()) {
            throw new AjaxBlocksException(
                "Method \"$controllerMethod\" of class \"$className\" is not public or is not callable.",
                AjaxBlocksErrorCodes::CONTROLLER_IS_NOT_CALLABLE
            );
        }

        return $controller->getParameters();
    }