代码之家  ›  专栏  ›  技术社区  ›  Beau Simensen

有可用的PHP DocBlock解析器工具吗[[关闭]

  •  15
  • Beau Simensen  · 技术社区  · 16 年前

    我想建立一些规模较小,但高度定制的几个项目文档网站。 PhpDocumentor 很好,但很重。我想尝试调整模板,但在花了短短的几分钟研究后,我认为这将是太多的工作。

    理想情况下,我希望看到一些东西,我可以传递一堆文件,让它返回所有的文件、类、属性和方法,以及它们的元数据,这样我就可以基于这些数据构建一些简单的模板。

    5 回复  |  直到 16 年前
        1
  •  23
  •   Gordon Haim Evgi    13 年前

    你可以很容易地做到这一点自己与 Reflection API:

    /**
     * This is an Example class
     */
    class Example
    {
        /**
         * This is an example function
         */
        public function fn() 
        {
            // void
        }
    }
    
    $reflector = new ReflectionClass('Example');
    
    // to get the Class DocBlock
    echo $reflector->getDocComment()
    
    // to get the Method DocBlock
    $reflector->getMethod('fn')->getDocComment();
    

    请参见本教程: http://www.phpriot.com/articles/reflection-api

    PEAR package 可以解析DocBlocks。

        2
  •  6
  •   Community Mohan Dere    9 年前

    以防有人需要正则表达式( xdazz suggested 来试试这个 student310 评论说(这对她/他的需要有效)

    if (preg_match_all('/@(\w+)\s+(.*)\r?\n/m', $str, $matches)){
      $result = array_combine($matches[1], $matches[2]);
    }
    

    示例( Demo ) :

    <?php
    $str ='
    /**    
     * @param   integer  $int  An integer
     * @return  boolean
     */
    ';
    if (preg_match_all('/@(\w+)\s+(.*)\r?\n/m', $str, $matches)){
      $result = array_combine($matches[1], $matches[2]);
    }
    
    var_dump($result);
    
        3
  •  5
  •   cvsguimaraes    12 年前

    只是为了更新答案。您可能还想查看 phpDocumentor2

        4
  •  3
  •   Community Mohan Dere    9 年前

    作为furgas pointed out ,我一直在用 phpDocumentor

    <?php
    $class = new ReflectionClass('MyClass');
    $phpdoc = new \phpDocumentor\Reflection\DocBlock($class);
    
    var_dump($phpdoc->getShortDescription());
    var_dump($phpdoc->getLongDescription()->getContents());
    var_dump($phpdoc->getTags());
    var_dump($phpdoc->hasTag('author'));
    var_dump($phpdoc->hasTag('copyright'));