Unique

PHP Annotation路由实现研究

<?php
class Controller
{
    /**
     * @Route("/index")
     */
    public function index()
    {
        echo 'index';
    }

    /**
     * @Route("/go")
     */
    public function go()
    {
        echo 'go';
    }
}

$controller = new Controller();
$a = new ReflectionClass($controller);
foreach ($a->getMethods() as $method) {
    preg_match("/@Route\(\"(.+)\"\)/", $method->getDocComment(), $ret);
    var_dump($ret[1]);
}

转载需经作者允许并注明出处(http://blog.hiunique.com/php/207.html)
来自:Unique

添加评论