jlabno / annotations-scanner
Annotated files scanner - looks for methods annotated with provided annotations, outputs an array of either filepaths or directories.
v1.2.1
2022-07-20 13:20 UTC
Requires
- php: ^7.4||^8.0
- composer/composer: ^2.2
- doctrine/annotations: ^1.13
- psr/simple-cache: ^1.0
- symfony/cache: ^5.4
Requires (Dev)
- phpunit/phpunit: ^8.5
README
Scanner looks for methods annotated with provided annotations, outputs an array of either filepaths or directories.
Installation
Step 1: Download the library using composer
Require package by composer
composer require jlabno/annotations-scanner
Step 2: How to use
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']
2. Optional features
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);