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

This package is auto-updated.

Last update: 2024-04-20 17:09:41 UTC


README

Scanner looks for methods annotated with provided annotations, outputs an array of either filepaths or directories.

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

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);