Scanner looks for methods annotated with provided annotations, outputs an array of either filepaths or directories.
Require package by composer
composer require jlabno/annotations-scanner
By default, library uses Apcu cache, you can pass your own cache implementation of Psr\SimpleCache
<?php
declare(strict_types=1);
use AnnotationsScanner\Scanner\ScannerFactory;
use AnnotationsScanner\Scanner\ScanResult;
use MyAnnotations\YourAnnotation;
use MyAnnotations\AnotherAnnotation;
$scanner = ScannerFactory::createWithDefaultReader(
'/app',
YourAnnotation::class,
AnotherAnnotation::class,
);
/**
* @returns ScanResult
*/
$result = $scanner->scan();
$foundFilePaths = $result->getFilePaths();
//['/app/src/classes/MyClass.php', '/app/src/classes/deeper/MyAnotherClass.php']
$foundDirectories = $result->getFileDirs();
//['/app/src/classes', '/app/src/classes/deeper']
You can use your own cache which implements Psr\SimpleCache
$cache = new \Symfony\Component\Cache\Psr16Cache(new \Symfony\Component\Cache\Adapter\NullAdapter());
$scanner = ScannerFactory::createWithDefaultReaderAndCache('/app', $cache);
You can use your own annotation reader compliant with Doctrine\Common\Annotations\Reader
$scanner = ScannerFactory::createWithAnnotationReader( '/app', $reader);
or with custom cache
$scanner = ScannerFactory::createWithAnnotationReaderAndCache( '/app', $reader, $cache);