uzbek/laravel-attribute-scanner

PHP8 Attribute scanner for Laravel project


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

PHP8 Attribute scanner for Laravel project

Installation

You can install the package via composer:

composer require uzbek/laravel-attribute-scanner

Usage

use Uzbek\LaravelAttributeScanner\Facades\AttributeScanner;

$attributes = AttributeScanner::getAttributes(asArray: true);

// or

use Uzbek\LaravelAttributeScanner\LaravelAttributeScanner;

$scanner = new LaravelAttributeScanner(directories: ['app/Models', 'app/Http/Controllers']);
$attributes = $scanner->getAttributes();

Result examples

asArray = false (default)

[
    "App\Http\Controllers\UserController@create" => [{...},{...}], #Uzbek\LaravelAttributeScanner\Attribute[],   (method)
    "App\Http\Controllers\UserController@update>id" => [{...}], #Uzbek\LaravelAttributeScanner\Attribute[],   (parameter)
    "App\Http\Controllers\UserController.service" => [{...}], #Uzbek\LaravelAttributeScanner\Attribute[],   (property)
]

asArray = true

[
    "App\Http\Controllers\UserController@create" => [
        [
            "class" => "App\Http\Controllers\UserController",
            "method" => "create",
            "target" => "method",
            "name" => "Uzbek\LaravelValidationAttributes\Attributes\Validators",
            "arguments" => [
                [
                    "name" => "required|string",
                    "email" => "required|email",
                    ...
                ],
            ],
        ]
    ],
    "App\Http\Controllers\UserController@update>id" => [
        [
            "class" => "App\Http\Controllers\UserController",
            "method" => "update",
            "target" => "parameter",
            "parameter" => "id",
            "name" => "Uzbek\SomeAttributes\ID",
            "arguments" => [],
        ]
    ],
    "App\Http\Controllers\UserController.service" => [
        [
            "class" => "App\Http\Controllers\UserController",
            "target" => "property",
            "property" => "service",
            "name" => "Uzbek\SomeAttributes\Readonly",
            "arguments" => [],
        ]
    ],
    "App\Http\Controllers\UserController:IS_PUBLIC" => [
        [
            "class" => "App\Http\Controllers\UserController",
            "target" => "constant",
            "constant" => "IS_PUBLIC",
            "name" => "Uzbek\SomeAttributes\Casts\Integer",
            "arguments" => [],
        ]
    ],
    ...
]

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.