首页 > 代码库 > PHP MVC自动RBAC访问路由自动生成

PHP MVC自动RBAC访问路由自动生成

使用关键点:

ReflectionClass


class Rbac extends MY_Controller
{

    public function index()
    {
        $arr = glob(  __DIR__ .DIRECTORY_SEPARATOR. '*.php');
//        $arr = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . '*');
        $MVC = array();
        foreach ($arr as $path) {

            $basename = basename($path, '.php');

            //仅支持合法的命名
            if (preg_match('/^\w+$/', $basename) && $path != __FILE__) {
                require $path;
                $className = ucfirst($basename);
                $ref = new ReflectionClass($className);
                foreach ($ref->getMethods() as $key => $methods) {

                    var_dump( get_class_methods($methods));

                    if($methods->isPublic()){
                        $MVC[$methods->class][] = array(
                            $methods->getName(),
                            $methods->getFileName(),
                        );
                            $methods->name;
                    }
                }
            }
        }
        var_dump($MVC);
    }
}