mirror of
https://github.com/Respect/Validation.git
synced 2026-03-14 14:25:45 +01:00
- Add PrefixMapGenerator to produce COMPOSABLE/COMPOSABLE_WITH_ARGUMENT constants from #[Mixin] attributes, replacing hand-written arrays - Move Prefix transformer to reference generated PrefixMap constants - Extract NamespaceScanner from MixinGenerator for shared directory scanning - Introduce FluentBuilder subnamespace for builder-chain generators (MixinGenerator, PrefixMapGenerator, MethodBuilder, Mixin attribute) - Add CodeGenerator interface and Config class as shared CodeGen contracts
44 lines
975 B
PHP
44 lines
975 B
PHP
<?php
|
|
|
|
/*
|
|
* SPDX-License-Identifier: MIT
|
|
* SPDX-FileCopyrightText: (c) Respect Project Contributors
|
|
* SPDX-FileContributor: Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Dev\CodeGen;
|
|
|
|
use DirectoryIterator;
|
|
use ReflectionClass;
|
|
|
|
use function ksort;
|
|
|
|
final class NamespaceScanner
|
|
{
|
|
/** @return array<string, ReflectionClass> */
|
|
public static function scan(string $directory, string $namespace): array
|
|
{
|
|
$nodes = [];
|
|
|
|
foreach (new DirectoryIterator($directory) as $file) {
|
|
if (!$file->isFile()) {
|
|
continue;
|
|
}
|
|
|
|
$className = $namespace . '\\' . $file->getBasename('.php');
|
|
$reflection = new ReflectionClass($className);
|
|
|
|
if ($reflection->isAbstract()) {
|
|
continue;
|
|
}
|
|
|
|
$nodes[$reflection->getShortName()] = $reflection;
|
|
}
|
|
|
|
ksort($nodes);
|
|
|
|
return $nodes;
|
|
}
|
|
}
|