for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
namespace inroutephp\inroute\Compiler;
/**
* @implements \IteratorAggregate<string>
*/
final class Psr4ClassFinder implements \IteratorAggregate
{
* @var string
private $directory;
private $prefix;
public function __construct(string $directory, string $prefix)
$this->directory = $directory;
if (!preg_match('/\\\$/', $prefix)) {
$prefix .= '\\';
}
$this->prefix = $prefix;
/** @return \Generator<string> */
public function getIterator(): \Generator
foreach (new \DirectoryIterator($this->directory) as $fileInfo) {
if ($fileInfo->isDot()) {
continue;
if ($fileInfo->isFile() && $fileInfo->getExtension() == 'php') {
yield $this->prefix . $fileInfo->getBasename('.php');
if ($fileInfo->isDir()) {
yield from new Psr4ClassFinder(
$this->directory . '/' . $fileInfo->getBasename(),
$this->prefix . $fileInfo->getBasename()
);