PHPackages                             mbunge/php-attributes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mbunge/php-attributes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mbunge/php-attributes
=====================

This package provides an easy way to use PHP 8 Attributes

3.1.0(5y ago)44314[1 issues](https://github.com/mbunge/php-attributes/issues)MITPHPPHP ^8.0.0

Since Dec 27Pushed 2y ago3 watchersCompare

[ Source](https://github.com/mbunge/php-attributes)[ Packagist](https://packagist.org/packages/mbunge/php-attributes)[ Docs](https://github.com/mbunge/php-attributes)[ RSS](/packages/mbunge-php-attributes/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (10)Used By (0)

PHP Attributes
==============

[](#php-attributes)

[![Total Downloads](https://camo.githubusercontent.com/914cf514bb52add3fb4904bf6d6a2e7625a493a0bfb1ba67b457373597853b18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d62756e67652f7068702d61747472696275746573)](https://packagist.org/packages/mbunge/php-attributes)[![Total Downloads](https://camo.githubusercontent.com/3d0f4900119491df77eadbd3f432d58fc5654a20487aab0be6abebc6aae3216c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d62756e67652f7068702d61747472696275746573)](https://packagist.org/packages/mbunge/php-attributes)[![Latest Stable Version](https://camo.githubusercontent.com/24d1b10f824dc860fb4e82a4bf5345625a9bd853103dfbfca734682ed6c74a5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d62756e67652f7068702d61747472696275746573)](https://packagist.org/packages/mbunge/php-attributes)[![License](https://camo.githubusercontent.com/8af9e79915d0956eaffcea4cc7ed4a276685bfb167a8b3d3d14e45a5f9bb11ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d62756e67652f7068702d61747472696275746573)](https://packagist.org/packages/mbunge/php-attributes)

This package provides an easy way to use and apply [PHP 8 Attributes](https://www.php.net/manual/en/language.attributes.php)and allows quick real-world implementations meta-data or annotation related features like Routes, Events, DB Relations.

Features
--------

[](#features)

- Apply PHP 8 attributes to a class and class components
- Automatically apply attributes to autoloaded classes
- Restrict attributes to filter condition of class name, namespace or class reflection

See [Upcoming features](https://github.com/mbunge/php-attributes/issues?q=is%3Aissue+is%3Aopen+label%3A%22upcoming+feature%22) of next release.

Concept
-------

[](#concept)

php-attributes uses a decorated composer autoloader and notifies a handler with loaded class name. The attributes for class components get resolved using reflections.

This package supports attributes for

- classes
- class constants
- class methods
- class method parameters
- class properties.

Install
-------

[](#install)

Via Composer

```
$ composer require mbunge/php-attributes
```

Usage
-----

[](#usage)

Instantiate the attribute handler `Mbunge\PhpAttributes\AttributeResolver` via factory `PhpAttributes\PhpAttributesFactory::createResolver()` or direct.

Attributes of traget class components get resolved by passed class name as string to `Mbunge\PhpAttributes\Resolver\AttributeResolver::resolve(string $class)`.

All resolved attributes returned as an array of data-transfer object (dto) `Mbunge\PhpAttributes\Resolver\ResolvedAttributesDto`.

```
