载入请求模板.

不存在模板文件或指定模板将返回一个空数组.

@param string $module 模块名
@param string $action 行为名
@param string $templateName 模板名

@return array
498056
public static function loadTemplate($module, $action, $templateName)
    {
        if ( ! is_string($module) || ! is_string($action) || ! is_string($templateName)) {
            return array();
        }
        if (($templates = self::loadCache($module, $action)) === false) {
            $filepath = Config::path("template/{$module}/") . $action . '.php';
            if ( ! file_exists($filepath)) {
                return array();
            }
            $templates = require $filepath;
            if ( ! is_array($templates)) {
                return array();
            }
            self::preserveCache($module, $action, $templates);
        }

        if (array_key_exists($templateName, $templates)) {
            return $templates[$templateName];
        }

        return array();
    }
1102745
public function createByTemplateName($templateName, $isFreeSchema = true, 
      $opts = array()) {
    $params = array(
        'action' => "create",
        'template' => $templateName,
    );

    if (isset($opts['desc']) && !empty($opts['desc'])) {
      $params['index_des'] = $opts['desc'];
    }
    
    if ($isFreeSchema == true) {
      $params['template_type'] = 1;
    } else {
      $params['template_type'] = 0;
    }
    
    return $this->client->call($this->path, $params);
  }
38598
public function checkLimitation ($module, $method)
	{
		
		// If no methods are defined or all is denied
		
		if (!$this->actionLimit || !Parser::_ak ($this->actionLimit, 'all', TRUE))
		{
			
			// Deny all
			
			return FALSE;
			
		}
		
		// If all methods are enabled
		
		if (Parser::_ak ($this->actionLimit, 'all', FALSE))
		{
			
			// Allow all
			
			return TRUE;
			
		}
		
		// If the module method is allowed
		
		if (Parser::_ak ($this->actionLimit, array ($module, $method), FALSE))
		{
			
			// Allow
			
			return TRUE;
			
		}
		
		// If the module is allowed
		
		if (Parser::_ak ($this->actionLimit, $module, FALSE) === TRUE)
		{
			
			// Allow
			
			return TRUE;
			
		}
		
		// Deny
		
		return FALSE;
		
	}
1129137
public function createUrl(string $moduleName, string $controllerName, string $actionName, ?DataMap $params = null): string
    {
        $url = '/';
        if (! $this->isModuleName($moduleName)) {
            Application::$app->dispatchEvent(ApplicationErrorEvent::createCustom(500, '模块名' . $moduleName . '非法'));
        }
        if (! $this->isControllerName($controllerName)) {
            Application::$app->dispatchEvent(ApplicationErrorEvent::createCustom(500, '控制器名' . $controllerName . '非法'));
        }
        if (! $this->isActionName($actionName)) {
            Application::$app->dispatchEvent(ApplicationErrorEvent::createCustom(500, '操作名' . $actionName . '非法'));
        }
        return $url;
    }
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('*');
        }
    }
336638
public static function generate_page(Module $module, string $action)
    {
        $settings = static::query()->where('module_name', $module->name)
            ->where('action', $action)->get()->makeFormFields();

        return [
            'module' => $module,
            'sections' => $settings->pluck('section')->unique(),
            'fieldsets' => $settings->pluck('fieldset')->unique(),
            'fields' => $settings->groupBy(['section', 'fieldset']),
        ];
    }
71138
static function ModuleCustomTemplatesFolder(TemplateModule $module)
    {
        $parentFolder = Path::Combine(PHINE_PATH, 'App/Phine/ModuleTemplates');
        $bundleFolder = Path::Combine($parentFolder, $module->MyBundle());
        return Path::Combine($bundleFolder, $module->MyName());
    }
410023
public static function getBaseReportUrl($module, $action, $queryParams = array())
    {
        $params = array_merge($queryParams, array('module' => $module, 'action' => $action));
        return Request::getCurrentUrlWithoutGenericFilters($params);
    }
1229058
function ReportTemplateAction($moduleType, $template, Enums\Action $action)
    {
        $logItem = $this->CreateLogItem(Enums\ObjectType::Template(), $action);
        $logTemplate = new LogTemplate;
        $logTemplate->SetLogItem($logItem);
        $logTemplate->SetModuleType($moduleType);
        $logTemplate->SetTemplate($template);
        $logTemplate->Save();
    }
76375
protected function ModuleTemplates($module)
    {
        $folder = PathUtil::ModuleCustomTemplatesFolder($module);
        if (!Folder::Exists($folder))
        {
            return array();
        }
        $templates = Folder::GetFiles($folder);
        $result = array();
        foreach ($templates as $template)
        {
            if (Path::Extension($template) == 'phtml')
            {
                $result[] = Path::RemoveExtension($template);
            }
        }
        return $result;
    }
11379
public function hasPermission($module, $action, User $user = null) {
		$module = $this->service->getModuleManager()->load($module);
		$action = $module->getActionModel($action);
		return $this->hasActionPermission($action, $user);
	}
1171249
static public function encode(?string $module = '', ?string $controller = "", ?string $action = "", ?array $params = []): string
    {
        // 配置中的根
        $url = configDefault('/', 'system', 'host');

        // 配置中的路由模式
        $mode = configDefault('传统模式', 'system', 'url_mode');

        //取默认MCA
        list($defaultM, $defaultC, $defaultA) = self::getMCADefault();

        //如果未提供,则使用默认值
        $module = $module ?: $defaultM;
        $controller = $controller ?: $defaultC;
        $action = $action ?: $defaultA;

        // 根据路由配置进行编码
        $router = configDefault([], 'router');
        foreach ($router as $key => $case) {
            // 这个不是路由配置,而是参数
            if (substr($key, 0, 1) == '_') continue;

            // 如果没有编码这个配置项
            if (!isset($case['encode']) or !$case['encode']) continue;

            //如果编码是一个方法
            if (is_callable($case['encode'])) {
                //调用 回调方法进行转义
                $return = $case['encode']($module, $controller, $action, $params);

                //如果不符合规则,下一条
                if (!$return) continue;

                //处理的结果
                list($pattern, $params) = $return;
                $params = $params ?: [];

                //转义后处理
                return self::encodeMatched($pattern, $params);
            }

            // 取配置,前三项为模块名,控制器,动作名称
            $rule = $case['encode'];
            list ($m, $c, $a) = $rule;

            // 如果控制器与动作相同,使用此规则
            if ($m == $module and $c == $controller and $a == $action) {
                // 把控制器名称和动作名称替换进去
                $pattern = str_replace(['{m}', '{c}', '{a}'], [$module, $controller, $action], $rule[3]);

                //转义后处理
                return self::encodeMatched($pattern, $params);
            }
        }

        // 例 /<m>/<c>/<a>/<k1>/<v1>/<k2>/<v2>/...
        if ($mode == '路径模式') {
            if ($module) $url .= $module . '/';

            // 附加控制器名和动作名
            if ($controller) {
                $url .= $controller . '/';
                if ($action) $url .= $action . '/';
            }

            // 附加参数
            foreach ($params as $key => $value) {
                if (!is_null($value)) $url .= $key . '/' . urlencode($value) . '/';
            }
            return trim($url, '?');
        }

        if ($mode == '传统模式') {
            // 例: /index.php?<k1>=<v1>&<k2=v2>...
            $url .= 'index.php';
        }

        $url .= '?';

        // 取三项参数名
        list ($mName, $cName, $aName) = self::$mcaName;

        // 附加模块名称
        if ($module) $url .= $mName . '=' . $module . '&';

        // 附加控制器名称
        if ($controller) $url .= $cName . '=' . $controller . '&';

        // 附加动作名称
        if ($action) $url .= $aName . '=' . $action . '&';

        // 附加参数
        foreach ($params as $key => $value) {
            $url .= $key . '=' . urlencode('' . $value) . '&';
        }
        return trim(trim($url, '&'), '?');
    }
1203465
protected static function firstMatchingModule($module_names, $target) {
		foreach ($module_names as $module) {
			if (stripos($module, $target) !== false) {
				return $module;
			}
		}
	}
302230
private function getDefaultVars(Template $template = null, $controller, $action)
    {
        if (0 !== count($arguments = $template->getVars())) {
            return $arguments;
        }

        if (!$template instanceof ViewAnnotation || $template->isPopulateDefaultVars()) {
            $r = new \ReflectionObject($controller);

            $arguments = array();
            foreach ($r->getMethod($action)->getParameters() as $param) {
                $arguments[] = $param->getName();
            }

            return $arguments;
        }
    }
893260
function short($action,$module,$bundle){

		if(is_array($this->get('routes'))){
			foreach($this->get('routes') as $r){ //precalculate short links
				if($bundle == $r['bundle'] && $module ==$r['default_module'] && $action==$r['default_action'] && !empty($r['short'])){

					return $r['short'];
				}
			}

			return "/".$bundle."/".$module."/".$action;
		}
		return "/".$bundle."/".$module."/".$action;
	}
1160285
private 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)) {
                    $this->getControllerFiles($module, $namespace . $file . '\\', $prefix . $file . '/', $result);
                } elseif (strcmp(substr($file, -14), 'Controller.php') === 0) {
                    $id = Inflector::camel2id(substr(basename($file), 0, -14));
                    $className = $namespace . Inflector::id2camel($id) . '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__);
    }
1115006
protected function actionListModule()
    {
        $this->controlToken('action');

        $action = $this->getQuery('action');
        $module_id = $this->getQuery('module_id');

        if (!empty($action) && !empty($module_id)) {
            $this->setModule($module_id);
            $result = $this->startActionModule($action);
            $this->finishActionModule($result);
        }
    }