php反射小试: 提取控制器的action方法
$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 ''; } }
?
1 楼 vb2005xu 2012-05-31 http://www.php10086.com/page/3 不错的博客
2 楼 vb2005xu 2012-05-31 http://opauth.org/
3 楼 vb2005xu 2012-06-01 http://www.shejidaren.com/category/css