jlabno / annotations-scanner
注释文件扫描器 - 查找带有提供注释的方法,输出文件路径或目录的数组。
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
扫描器查找带有提供注释的方法,输出文件路径或目录的数组。
安装
步骤 1:使用 composer 下载库
通过 composer 需求包
composer require jlabno/annotations-scanner
步骤 2:如何使用
默认情况下,库使用 Apcu 缓存,您可以通过传递自己的 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. 可选功能
您可以使用实现 Psr\SimpleCache
的自己的缓存。
$cache = new \Symfony\Component\Cache\Psr16Cache(new \Symfony\Component\Cache\Adapter\NullAdapter()); $scanner = ScannerFactory::createWithDefaultReaderAndCache('/app', $cache);
您可以使用符合 Doctrine\Common\Annotations\Reader
的自己的注释读取器
$scanner = ScannerFactory::createWithAnnotationReader( '/app', $reader);
或自定义缓存
$scanner = ScannerFactory::createWithAnnotationReaderAndCache( '/app', $reader, $cache);