Search code examples
phpapigen

Does ApiGen 5 support multiple file extensions?


I am using ApiGen 5.0.0-RC3, and I cannot figure out how to get it to search for .class files and .inc files as well as .php files.

My question is twofold: firstly, is it possible to get ApiGen to recognize .class files, and secondly, if it is possible, how would one go about it?


Solution

  • I found a way... but it's pretty hacky. I'm posting it here in the hopes that it might be able to help someone else.

    The solution is not actually in ApiGen, but in roave/better-reflection. Specifically, in the file src/SourceLocator/Type/FileIteratorSourceLocator.php, in the method getAggregatedSourceLocator, in an anonymous function.

    Replace:

    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)
        ))));
    }
    

    With:

    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)
        ))));
    }
    

    Works as of commit 47b76f7, version something