1. Go to this page and download the library: Download componenta/class-finder library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
componenta / class-finder example snippets
use Componenta\ClassFinder\ClassFinder;
use Componenta\ClassFinder\Filter\InstantiableFilter;
use Componenta\ClassFinder\Filter\PatternFilter;
$finder = new ClassFinder([
PatternFilter::endsWith('Controller'),
new InstantiableFilter(),
]);
$controllers = $finder->find(__DIR__ . '/src', exclude: ['tests']);
foreach ($controllers as $file => $classInfo) {
echo $classInfo->fullyQualifiedName . PHP_EOL;
}
use Componenta\ClassFinder\ClassFinder;
use Componenta\Filter\PredicateInterface;
$controllers = new class implements PredicateInterface {
public function accept(mixed $value, string|int|null $key = null): bool
{
return str_ends_with($value->name, 'Controller');
}
};
$finder = new ClassFinder($controllers);
use Componenta\ClassFinder\Filter\PatternFilter;
new PatternFilter('*Controller'); // class name suffix
new PatternFilter('User*'); // class name prefix
new PatternFilter('App\\User'); // exact fully-qualified class name
new PatternFilter('*\\Api\\*Controller'); // fully-qualified wildcard pattern
PatternFilter::exactMatch('UserController');
PatternFilter::namespace('App\\Http'); // namespace and children
PatternFilter::exactNamespace('App\\Http\\Admin'); // exact namespace only
PatternFilter::exactFqn('App\\Http\\UserController');
PatternFilter::fqn('App\\*\\*Controller');
PatternFilter::in(['UserController', 'PostController']);
use Componenta\ClassFinder\Filter\AttributePatternFilter;
use Componenta\ClassFinder\Filter\AttributeSearchFilter;
use Componenta\ClassFinder\Filter\AnyAttributeFilter;
AttributeSearchFilter::hasAttribute(Route::class);
AttributeSearchFilter::hasAnyAttribute([Route::class, Command::class]);
AttributeSearchFilter::hasAllAttributes([Cache::class, Validate::class]);
AttributeSearchFilter::hasAttribute(Inject::class, deepSearch: true);
new AttributePatternFilter('*Attribute', deepSearch: true);
AttributePatternFilter::attributePrefix('App\\Attribute\\');
new AnyAttributeFilter([Route::class, Command::class], deepSearch: true);
use Componenta\ClassFinder\FinalizableListenerInterface;
use Componenta\Tokenizer\ClassInfo;
final class RouteCollector implements FinalizableListenerInterface
{
/** @var list<class-string> */
private array $routes = [];
public function handle(ClassInfo $info): void
{
if ($info->reflector->getAttributes(Route::class) !== []) {
$this->routes[] = $info->fullyQualifiedName;
}
}
public function finalize(): void
{
// Build final registry or cache.
}
}
$config = (new Componenta\ClassFinder\ConfigProvider())();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.