Get list controller under module
@param \yii\base\Module $module
@param string $namespace
@param string $prefix
@param mixed $result
@return mixed
350925
protected function getControllerFiles($module, $namespace, $prefix, &$result)
    {
        $path = Yii::getAlias('@' . str_replace('\\', '/', $namespace), false);
        $token = "Get controllers from '$path'";
        Yii::beginProfile($token, __METHOD__);
        try {
            if (!is_dir($path)) {
                return;
            }
            foreach (scandir($path) as $file) {
                if ($file == '.' || $file == '..') {
                    continue;
                }
                if (is_dir($path . '/' . $file) && preg_match('%^[a-z0-9_/]+$%i', $file . '/')) {
                    $this->getControllerFiles($module, $namespace . $file . '\\', $prefix . $file . '/', $result);
                } elseif (strcmp(substr($file, -14), 'Controller.php') === 0) {
                    $baseName = substr(basename($file), 0, -14);
                    $name = strtolower(preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $baseName));
                    $id = ltrim(str_replace(' ', '-', $name), '-');
                    $className = $namespace . $baseName . 'Controller';
                    if (strpos($className, '-') === false && class_exists($className) && is_subclass_of($className, 'yii\base\Controller')) {
                        $this->getControllerActions($className, $prefix . $id, $module, $result);
                    }
                }
            }
        } catch (\Exception $exc) {
            Yii::error($exc->getMessage(), __METHOD__);
        }
        Yii::endProfile($token, __METHOD__);
    }
1037895
protected function prepareList($result, array $options)
    {
        $handlers = $this->getHandlers();

        if (empty($result['data'])) {
            $result['data'] = $handlers;
        } else {
            $result['data'] = array_replace_recursive($handlers, $result['data']);
        }

        foreach ($result['data'] as $handler_id => &$handler) {

            if (!empty($options['active']) && empty($handler['status'])) {
                unset($result['data'][$handler_id]);
                continue;
            }

            try {
                $handler['data'] = (array) $this->callHandler($handler_id);
            } catch (Exception $ex) {
                $handler['data'] = array();
            }
        }

        gplcart_array_sort($result['data']);
        return $result;
    }
1261647
protected static function getControllersList($paths, $namespaces_list)
    {
        $controllers = array();
        foreach ($paths as $p_index => $p) {
            if (!file_exists($p)) {
                throw new TaskManagerException('folder ' . $p . ' does not exist');
            }
            $files = scandir($p);
            foreach ($files as $f) {
                if (preg_match('/^([A-Z]\w+)\.php$/', $f, $match)) {
                    $namespace = isset($namespaces_list[$p_index]) ? $namespaces_list[$p_index] : '';
                    $controllers[] = $namespace . $match[1];
                }
            }
        }
        return $controllers;
    }
70687
public function getRoutable($controller, $prefix)
    {
        $routable = [];
        $reflection = new ReflectionClass($controller);
        $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
        // To get the routable methods, we will simply spin through all methods on the
        // controller instance checking to see if it belongs to the given class and
        // is a publicly routable method. If so, we will add it to this listings.
        foreach ($methods as $method) {
            if ($this->isRoutable($method)) {
                $data = $this->getMethodData($method, $prefix);
                $routable[$method->name][] = $data;
                // If the routable method is an index method, we will create a special index
                // route which is simply the prefix and the verb and does not contain any
                // the wildcard place-holders that each "typical" routes would contain.
                if ($data['plain'] == $prefix.'/index') {
                    $routable[$method->name][] = $this->getIndexData($data, $prefix);
                }
            }
        }
        return $routable;
    }
52951
protected function getRightsFromMap($controller, $action, $module) {
        list ($rController, $allController) = $this->getRawAndModuleControllers($controller, $module);
        if (isset($this->finalMap[$rController][$action])) {
            return $this->finalMap[$rController][$action];
        } elseif (isset($this->finalMap[$allController][$action])) {
            return $this->finalMap[$allController][$action];
        } elseif (isset($this->finalMap[$rController]['*'])) {
            return $this->finalMap[$rController]['*'];
        } elseif (isset($this->finalMap[$allController]['*'])) {
            return $this->finalMap[$allController]['*'];
        } elseif (isset($this->finalMap['*'][$action])) {
            return $this->finalMap['*'][$action];
        } elseif (isset($this->finalMap['*']['*'])) {
            return $this->finalMap['*']['*'];
        } else {
            return array('*');
        }
    }
649073
protected function resolveModule($controller)
    {
        $modules = $this->getModules();

        $module = get_class($controller);
        while (false !== $pos = strrpos($module, '\\')) {
            $module = substr($module, 0, $pos);
            if ($modules->has($module)) {
                return $module;
            }
        }

        throw new RuntimeException(sprintf(
            'Failed to resolve the module namespace of the "%s" controller.',
            get_class($controller)
        ));
    }
1361309
public function getController() {
        $module = $this->getModule();
        $namespace = $module->getController($this->getParam('controller'));

        /** @type \Titon\Controller\Controller $controller */
        $controller = new $namespace($this->getParams());
        $controller->setRequest($this->getRequest());
        $controller->setResponse($this->getResponse());

        if ($controller instanceof UseApplication) {
            $controller->setApplication($this->getApplication());
        }

        if ($controller instanceof UseModule) {
            $controller->setModule($module);
        }

        if (method_exists($controller, 'initialize')) {
            $controller->initialize();
        }

        return $controller;
    }
1005467
public function getList(PageInterface $current = null, $level = 0, $rawRoutes = false, $showAll = true, $showFullpath = false, $showSlug = false, $showModular = false, $limitLevels = false)
    {
        if (!$current) {
            if ($level) {
                throw new \RuntimeException('Internal error');
            }

            $current = $this->root();
        }

        $list = [];

        if (!$current->root()) {
            if ($rawRoutes) {
                $route = $current->rawRoute();
            } else {
                $route = $current->route();
            }

            if ($showFullpath) {
                $option = $current->route();
            } else {
                $extra  = $showSlug ? '(' . $current->slug() . ') ' : '';
                $option = str_repeat('&mdash;-', $level). '&rtrif; ' . $extra . $current->title();


            }

            $list[$route] = $option;


        }

        if ($limitLevels === false || ($level+1 < $limitLevels)) {
            foreach ($current->children() as $next) {
                if ($showAll || $next->routable() || ($next->modular() && $showModular)) {
                    $list = array_merge($list, $this->getList($next, $level + 1, $rawRoutes, $showAll, $showFullpath, $showSlug, $showModular, $limitLevels));
                }
            }
        }

        return $list;
    }
350974
public function findByModule(ModuleInterface $module = null, array $orderBy = null, $limit = null, $offset = null)
    {
        $criteria = [];

        if ($this->isModular($module)) {
            $criteria['module'] = $module;
        }

        /** @var EntityRepository $this */
        return $this->findBy($criteria, $orderBy, $limit, $offset);
    }
807112
protected function makeController($name, $module, $is_module = false) {
        return ModuleGenerator::renderTemplate('Controller', [
            'module' => $module,
            'name' => $name,
            'is_module' => $is_module
        ]);
    }
1184934
public static function factory($prefix, $name = null)
    {
        $calledClass = get_called_class();

        /** @var \PhalconRest\Api\ApiCollection $collection */
        $collection = new $calledClass($prefix);

        if ($name) {
            $collection->name($name);
        }

        return $collection;
    }
1089765
public function controller($controller_name)
    {
        // Retrieving the class and method to launch.
        if (is_null($controller_name)) {
            return null;
        }

        $parts = preg_split('/::|@/', $controller_name);

        if (count($parts) == 1) {
            $parts[1] = '__invoke';
        }

        list($class, $method) = $parts;

        if (!class_exists($class, true)) {
            $class = sprintf('%s\\%s', $this->namespaces['controller'], ucfirst($class));
        }

        $injections = $this->injector($class, $method);

        return [
            'action' => [new $class(), $method],
            'injection' => $injections
        ];
    }
1242336
private function getControllerClasses(\common_ext_Extension $extension) {
        $returnValue = array();

        // routes
        $namespaces = array();
        foreach ($extension->getManifest()->getRoutes() as $mapedPath => $ns) {
            if (is_string($ns)) {
                $namespaces[] = trim($ns, '\\');
            }
        }
        if (!empty($namespaces)) {
            common_Logger::t('Namespace found in routes for extension '. $extension->getId() );
            $classes = array();
            $recDir = new RecursiveDirectoryIterator($extension->getDir());
            $recIt = new RecursiveIteratorIterator($recDir);
            $regexIt = new RegexIterator($recIt, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
            foreach ($regexIt as $entry) {
                $info = helpers_PhpTools::getClassInfo($entry[0]);
                if (!empty($info['ns'])) {
                    $ns = trim($info['ns'], '\\');
                    if (!empty($info['ns']) && in_array($ns, $namespaces)) {
                        $returnValue[$info['class']] = $ns.'\\'.$info['class'];
                    }
                }
            }
        }

        // legacy
        if ($extension->hasConstant('DIR_ACTIONS') && file_exists($extension->getConstant('DIR_ACTIONS'))) {
            $dir = new DirectoryIterator($extension->getConstant('DIR_ACTIONS'));
            foreach ($dir as $fileinfo) {
                if(preg_match('/^class\.[^.]*\.php$/', $fileinfo->getFilename())) {
                    $module = substr($fileinfo->getFilename(), 6, -4);
                    $returnValue[$module] = $extension->getId().'_actions_'.$module;
                }
            }
        }

        $returnValue = array_filter( $returnValue, array($this, 'isControllerClassNameValid') );

        return (array) $returnValue;
    }
985191
public function getAppRoutes($module = null)
    {
        if ($module === null) {
            $module = Yii::$app;
        } elseif (is_string($module)) {
            $module = Yii::$app->getModule($module);
        }
        $key = [__METHOD__, Yii::$app->id, $module->getUniqueId()];
        $cache = Configs::instance()->cache;
        if ($cache === null || ($result = $cache->get($key)) === false) {
            $result = [];
            $this->getRouteRecursive($module, $result);
            if ($cache !== null) {
                $cache->set($key, $result, Configs::instance()->cacheDuration, new TagDependency([
                    'tags' => self::CACHE_TAG,
                ]));
            }
        }

        return $result;
    }
694477
protected function loadDataForPrefix($namespace, $prefix)
    {
        $this->failOnMissingNamespace($namespace);

        if (!isset($this->cachedData[$namespace])) {
            $this->cachedData[$namespace] = [];
        }

        if (!isset($this->cachedData[$namespace][$prefix])) {
            $this->cachedData[$namespace][$prefix] = [];
        }

        foreach ($this->addedData[$namespace] as $data) {

            if (isset($data[$prefix])) {
                $this->cachedData[$namespace][$prefix][] = $data[$prefix];
            }
        }

        return $this->cachedData[$namespace][$prefix];
    }
1128777
public function deactivateModule($namespace)
    {
        $namespace = Framework::prepareNamespace($namespace);

        // If the module isn't activated we have nothing to deactivate
        if (!isset($this->activatedModules[$namespace])) {
            return false;
        }
        
        // Load the module to deactivate it
        $namespace = Framework::prepareNamespace($namespace);
        $module = $this->getModule($namespace);

        // If the module isn't initialized it isn't active
        if ($module === false) {
            return false;
        }
        
        // Deactivate the module
        $module->deactivate();
        
        // Remove the module and save the module cache
        unset($this->activatedModules[$namespace]);
        unset($this->modules[$namespace]);
        $this->saveActivatedModules();
        
        return true;
    }
63377
public function getNamespaceList()
    {
        if (!isset($this->_namespaceList)) $this->getBasePathList();
        static::$_modulesNs[$this::className()] = $this->_namespaceList;
        return $this->_namespaceList;
    }