PHP反照小试: 提取控制器的action方法
PHP反射小试: 提取控制器的action方法
<?php /** * Acl 资源查询器 * * 在指定的 控制器目录中查找 对应的: * * 控制器 以及其 action 列表 * 并对 控制器 已经action 注释中的 @aclres-finder-desc{ 你的注释 }aclres-finder-desc@ * 做自动提取 * * 开发者只需在 控制器类文件中 进行对应的标述,即可... 基本就解决了 手动提取的工作了 :-) * * @author 色色 * @version 0.1 * */ class Pkg_Reflection_AclResource_Searcher { static function loadControllerList($basepath){ $paths = Core_AppUtils::recursion_glob($basepath,'*.php'); if (empty($paths)) return array(); foreach ($paths as $k => $v){ // 1. 去掉基准路径 $v = str_replace($basepath,'',$v); // 2. 去掉后缀 $v = preg_replace('/\.php$/i','',$v); // 3. 拆分过滤 $v = Core_AppUtils::normalize($v,DIRECTORY_SEPARATOR); if (empty($v)) continue; $paths[$k] = implode('_',$v); } $d = array(); foreach ($paths as $controller){ $d[$controller] = self::getActionListFromControllerClass($controller); } return $d; } static function getActionListFromControllerClass($controller_name){ static $controllerClassPrefix = null; if (!$controllerClassPrefix) { $controllerClassPrefix = Core_App::ini('mvc/web/dispatcher/controllerClassPrefix','Core_Controller_'); } $clazz = "{$controllerClassPrefix}{$controller_name}"; Core_Autoloader::loadClass($clazz,true); $obj = new ReflectionClass($clazz); $d = array(); $publicMethods = $obj->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($publicMethods as $method){ if (preg_match('/^action/i',$method->name)) { $action_name = preg_replace('/^action/i','',$method->name); $rmd = Core_Mvc_Router::resourceEncode($controller_name,$action_name); $q = array_shift($rmd); $d[$q] = self::getAclResourceDescription($method->getDocComment()); } } return array( 'description' => self::getAclResourceDescription($obj->getDocComment()), 'actions' => $d ); } static function getAclResourceDescription($finder){ static $tagfinder_start = '@aclres-finder-desc{'; static $tagfinder_end = '}aclres-finder-desc@'; if (empty($finder)) return ''; $start = stripos($finder,$tagfinder_start); if ($start){ $end = stripos($finder,$tagfinder_end); if ($end && $end > $start){ // 只有闭合的标签才行 $start = $start+strlen($tagfinder_start); return trim(substr($finder,$start,$end-$start)); } } return ''; } }

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



When a SpringBoot novice creates a project, the Controller cannot be scanned for a series of problems 1.2.3.4.5.6. Another way is to add @ComponentScan(basePackages={"xxx.xxx.xx","xxx.xxx" when starting the service class) .xx”}) is the fully qualified name of the package, which can be used for multiple SpringBoot custom controllers. The SpringBoot custom controller route cannot be scanned and cannot be found because the startup class and the custom Controller package are not in the same directory. Officially recommended placement of application.java

Solution to docker start failure: 1. Check the running status, and then release the occupied memory through the "echo 3 > /proc/sys/vm/drop_caches" command; 2. Use "$netstat -nltp|grep .. ." command to check whether the port has been occupied. If it is found to be occupied after going online, change it to an available port and restart.

DJI has not confirmed any plans to introduce a new action camera yet. Instead, it seems that GoPro will get ahead of its rival this year, having teased that it will introduce two new action cameras on September 4. For context, these are expected to a

Preface In some cases, the prefixes in the service controller are consistent. For example, the prefix of all URLs is /context-path/api/v1, and a unified prefix needs to be added to some URLs. The conceivable solution is to modify the context-path of the service and add api/v1 to the context-path. Modifying the global prefix can solve the above problem, but there are disadvantages. If the URL has multiple prefixes, for example, some URLs require prefixes. If it is api/v2, it cannot be distinguished. If you do not want to add api/v1 to some static resources in the service, it cannot be distinguished. The following uses custom annotations to uniformly add certain URL prefixes. one,

Create new text files in folders on Mac using Automator Automator is a powerful application that allows you to write scripts and automate. In this case, we will create an Automator Quick Action that can be run from anywhere in the Finder to create a new text file in the current folder location. So with a little setup, you can easily access the ability to create new text files anytime, anywhere. Open the Automator app on your Mac and select Create a new "Quick Action" Use the search function and search for "AppleScript" then double click or will run AppleScri

Solution to node start error: 1. Execute "node xx.js" directly in the terminal; 2. Add start startup item "scripts": {"test": "echo \"Error: no test specified\" && exit 1 ","start":"node service.js"}"; 3. Re-execute "npm start".

Almost a year has passed since DJI released the Osmo Action 4 (curr. $299 on Amazon). Since then, the company has focused on its other divisions, including new RS camera gimbals. On top of that, it has introduced various drones as well like the Avata

When using the PHP framework, you often encounter errors such as "PHPFatalerror: Class'Controller'notfound". This kind of error is usually related to the naming, location or loading of files in the framework, especially when you try to use controllers. This article will introduce several common processing methods to solve this problem. Confirm file location First, you need to confirm that the controller file is located in the correct directory for the framework. For example, if you are using the Laravel framework
