PHPackages                             atomino/util-attr - 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. atomino/util-attr

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

atomino/util-attr
=================

PHP Attribute handler

1.0(4y ago)0672MITPHP

Since Mar 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/atomino-framework/util-attr)[ Packagist](https://packagist.org/packages/atomino/util-attr)[ RSS](/packages/atomino-util-attr/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (2)

Attribute utility
=================

[](#attribute-utility)

Work easily with PHP8 Attributes!

```
get(\ReflectionClass|\ReflectionMethod|string $reflection, string|null $method = null):static|null
all(\ReflectionClass|\ReflectionMethod|string $reflection, string|null $method = null):static|null
collect(\ReflectionClass|\ReflectionMethod ...$reflections):static[]
```

Create Attributes
-----------------

[](#create-attributes)

Create the `Attribute` class as usual, just extend it from the `\Atomino\Neutrons\Attr` class.

```
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class MyAttr extends \Atomino\Neutrons\Attr
{
  public function __construct(public string $name){...}
}

#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class MyRepeatableAttr extends \Atomino\Neutrons\Attr
{
  public function __construct(public string $name){...}
}
```

Add the attribute to a class or a method

```
#[MyAttr("my awesome class")]
#[MyRepeatableAttr("my awesome class")]
class MyClass
{
  #[MyAttr("my awesome method")]
  #[MyRepeatableAttr("my awesome method")]
  #[MyRepeatableAttr("my awesome method two")]
  public function myMethod(){...}
}
```

Query Single Attribute (`get`)
------------------------------

[](#query-single-attribute-get)

```
get(\ReflectionClass|\ReflectionMethod|string $reflection, string|null $method = null):static|null
```

> As a return value you will get an Attribute instance or null

### Reflection based query

[](#reflection-based-query)

Then get the attribute based on the reflection of the class or method. The IDE will know what type of attribute you requested, the code completion will work.

```
$classRef = new ReflectionClass(MyClass::class);
$attr = MyAttr::get($classRef);
echo $attr->name;

$methodRef = $classRef->getMethod("myMethod");
$attr = MyAttr::get($methodRef);
echo $attr->name;
```

### Name based query

[](#name-based-query)

If you don't want to use reflection, you can get the attribute by the class (and the method) name.

```
$attr = MyAttr::get(MyClass::class);
echo $attr->name;

$attr = MyAttr::get(MyClass::class, "myMethod");
echo $attr->name;
```

Query Repeatable Attribute (`all`)
----------------------------------

[](#query-repeatable-attribute-all)

```
all(\ReflectionClass|\ReflectionMethod|string $reflection, string|null $method = null):static|null
```

> As a return value you will get an array with the Attribute instances in it

### Reflection based query

[](#reflection-based-query-1)

Then get the array of attributes based on the reflection of the class or method. The IDE will know what type of attribute you requested, the code completion will work.

```
$classRef = new ReflectionClass(MyClass::class);
$attrs = MyRepeatableAttr::all($classRef);
foreach ($attrs as $attr) echo $attr->name;

$methodRef = $classRef->getMethod("myMethod");
$attrs = MyRepeatableAttr::all($methodRef);
foreach ($attrs as $attr) echo $attr->name;
```

### Name based query

[](#name-based-query-1)

If you don't want to use reflection, you can get the attributes by the class (and the method) name.

```
$attrss = MyRepeatableAttr::all(MyClass::class);
foreach ($attrs as $attr) echo $attr->name;

$attrs = MyRepeatableAttr::all(MyClass::class, "myMethod");
foreach ($attrs as $attr) echo $attr->name;
```

Query attributes of multiple reflections (`collect`)
----------------------------------------------------

[](#query-attributes-of-multiple-reflections-collect)

```
collect(\ReflectionClass|\ReflectionMethod ...$reflections):static[]
```

> As a return value you will get an array with the Attribute instances in it

If you want to retrieve the attributes of multiple classes or methods in bulk, you can do so using the `collect` method.

```
$classRef = new ReflectionClass(MyClass::class);
$methodRefs = $classRef->getMethods();
$attrs = MyAttr::collect($classRef, ...$methodRefs);
foreach ($attrs as $attr) echo $attr->name;
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1521d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/66d6c319c7aaec0983a01e417b163694e8dca501b6a8ec82e1f5e2a03c88b2d6?d=identicon)[elvis](/maintainers/elvis)

---

Top Contributors

[![laborci](https://avatars.githubusercontent.com/u/7274872?v=4)](https://github.com/laborci "laborci (12 commits)")

---

Tags

php attribute

### Embed Badge

![Health badge](/badges/atomino-util-attr/health.svg)

```
[![Health](https://phpackages.com/badges/atomino-util-attr/health.svg)](https://phpackages.com/packages/atomino-util-attr)
```

###  Alternatives

[markshust/magento2-module-layouthandlelogger

The LayoutHandleLogger module displays layout handles when in developer mode.

1611.1k](/packages/markshust-magento2-module-layouthandlelogger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
