ApiGen 5支持多个文件扩展名吗?

时间:2017-07-27 18:20:43

标签: php apigen

我正在使用ApiGen 5.0.0-RC3,我无法弄清楚如何搜索.class文件和.inc文件以及.php文件。

我的问题有两个:首先,是否有可能让ApiGen识别.class个文件,其次,如果有可能,会怎么做呢?

1 个答案:

答案 0 :(得分:0)

我找到了一种方法......但它非常hacky。我在这里发帖,希望它可以帮助别人。

解决方案实际上不在ApiGen中,而是在roave/better-reflection中。具体来说,在文件src/SourceLocator/Type/FileIteratorSourceLocator.php中,在方法getAggregatedSourceLocator中,在匿名函数中。

替换:

private function getAggregatedSourceLocator() : AggregateSourceLocator
{
    return $this->aggregateSourceLocator ?: new AggregateSourceLocator(array_values(array_filter(array_map(
        function (\SplFileInfo $item) : ?SingleFileSourceLocator {
-            if (! ($item->isFile() && pathinfo($item->getRealPath(), \PATHINFO_EXTENSION) === 'php')) {
                 return null;
             }
            return new SingleFileSourceLocator($item->getRealPath());
        },
        iterator_to_array($this->fileSystemIterator)
    ))));
}

使用:

private function getAggregatedSourceLocator() : AggregateSourceLocator
{
    return $this->aggregateSourceLocator ?: new AggregateSourceLocator(array_values(array_filter(array_map(
        function (\SplFileInfo $item) : ?SingleFileSourceLocator {
+            $flag = in_array(pathinfo($item->getRealPath(), \PATHINFO_EXTENSION), ['php', 'class']);
+            if (! ($item->isFile() && $flag)) {
                 return null;
             }
            return new SingleFileSourceLocator($item->getRealPath());
        },
        iterator_to_array($this->fileSystemIterator)
    ))));
}

从提交47b76f7开始,版本某事