New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

annotation/larscan

Implement a Laravel scanner that can scan by namespace or path and instantiate classes annotated with specific annotations based on PHP 8.0's annotation feature.
2,067
Install
composer require annotation/larscan
Latest Version:1.1.1
PHP:^8.0
Laravel:8 – 13
License:MIT
Last Updated:Oct 2, 2026
Links: GitHub  ·  Packagist
Maintainer: jundayw

Annotation Scannable

Implement a Laravel scanner that can scan by namespace or path and instantiate classes annotated with specific annotations based on PHP 8.0's annotation feature.

GitHub Tag Total Downloads Packagist Version Packagist PHP Version Support Packagist License

Installation

You can install the package via Composer:

composer require annotation/larscan

Usage

Instantiation method

use Annotation\Scannable\Attributes\Scan;
use Annotation\Scannable\Attributes\ScanFile;
use Annotation\Scannable\Attributes\ScanNamespace;
use Annotation\Scannable\Attributes\ScanPath;
use Annotation\Scannable\Attributes\ScanPackageNamespace;

public function scan(): void
{
    // ScanPackageNamespace
    $scan = new ScanPackageNamespace(['GuzzleHttp']);
    
    // ScanNamespace
    $scan = new ScanNamespace(['Illuminate\Support\Arr']);
    $scan = new ScanNamespace(['Illuminate\Support*']);
    
    // ScanPath
    $scan = new ScanPath(__DIR__.'/../Http/');
    $scan = new ScanPath(new \RecursiveDirectoryIterator(__DIR__.'/../Http/Controllers'));
    
    // ScanFile
    $scan = new ScanFile(__FILE__);
    $scan = new ScanFile(new \SplFileInfo(__DIR__ . '/AppServiceProvider.php'));
    
    // Scan
    $scan = new Scan('Illuminate\Support\Arr');
    $scan = new Scan(['Illuminate\Support\Arr']);
    $scan = new Scan(new \ReflectionClass('Illuminate\Support\Arr'));
}

Annotation method

Only supports Laravel framework

use Annotation\Scannable\Attributes\Scan;
use Annotation\Scannable\Attributes\ScanFile;
use Annotation\Scannable\Attributes\ScanNamespace;
use Annotation\Scannable\Attributes\ScanPath;
use Annotation\Scannable\Attributes\ScanPackageNamespace;
use Rfc\Scannable\Contracts\Scannable;

#[ScanPackageNamespace(['GuzzleHttp'])]

#[ScanNamespace(['Illuminate\Support\Arr'])]
#[ScanNamespace(['Illuminate\Support*'])]

#[ScanPath(__DIR__.'/../Http/')]
#[ScanPath(new \RecursiveDirectoryIterator(__DIR__.'/../Http/Controllers'))]

#[ScanFile(__FILE__)]
#[ScanFile(new \SplFileInfo(__DIR__ . '/AppServiceProvider.php'))]

#[Scan('Illuminate\Support\Arr')]
#[Scan(['Illuminate\Support\Arr'])]
#[Scan(new \ReflectionClass('Illuminate\Support\Arr'))]
class AppServiceProvider extends ServiceProvider implements Scannable
{
    //
}
use Annotation\Scannable\Attributes\ScanNamespace;
use Annotation\Scannable\Attributes\ScanPackageNamespace;
use Annotation\Scannable\Contracts\Scanner;
use Annotation\Scannable\Facades\Scan;

public function scan(Scanner $scan): void
{
    $namespace = $scan->using(ScanPackageNamespace::class, function (ScanPackageNamespace $scanNamespace) {
        return $scanNamespace->getReflectionClass();
    });
    //dump($namespace);
    $namespace = Scan::using(ScanNamespace::class, function (ScanNamespace $namespace) {
        return $namespace->getNamespace();
    });
    //dump($namespace);
}

License

Nacosvel Contracts is made available under the MIT License (MIT). Please see License File for more information.

Related Packages

helgesverre/receipt-scanner

Use OpenAI to extract structured receipt and invoice data from Text, Html, Image...

9,751 145
thettler/laravel-console-toolkit

This Package provides some usefully console features like the attribute syntax f...

4,095 32
performing/laravel-field-attributes

This is my package laravel-field-attributes

2,269 1
cspray/annotated-container

Create Dependency Injection containers configured with PHP8 Attributes.

1,533 42
pijler/lang-scanner

An application for scanning files and updating translations.

1,495 4

Version History

Version Released PHP Laravel License
1.1.1 ^8.0 >=8.0.0 MIT
v1.1.0 ^8.0 >=8.0.0 MIT
v1.0.0 ^8.0 >=8.0.0 MIT
Pre-releases (1)
Version Released PHP License
v1.0.0-alpha ^8.0 MIT