PHPackages                             timostamm/data-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. timostamm/data-attributes

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

timostamm/data-attributes
=========================

09PHP

Since Oct 4Pushed 8y ago1 watchersCompare

[ Source](https://github.com/timostamm/data-attributes)[ Packagist](https://packagist.org/packages/timostamm/data-attributes)[ RSS](/packages/timostamm-data-attributes/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Attributes data structure
=============================

[](#php-attributes-data-structure)

This library provides a simple attribute lookup, editable attributes and namespaced attributes.

It is intended to be used by other libraries and makes it easy to implement with the provided Traits.

Readonly Attributes Collection
------------------------------

[](#readonly-attributes-collection)

```
use TS\Data\Attributes;

$attr = new Attributes(['target' => '_blank']);
$attr->count(); // => 1
count($attr); // => 1
$attr->get('target'); // => "_blank"
$attr->has('target'); // => true
$attr->toArray(); // => ['target' => '_blank']
foreach ($attr as $k => $v) {
  print $k . '=' . $v; // => "target = _blank"
}
```

Mutable Attributes Collection
-----------------------------

[](#mutable-attributes-collection)

```
use TS\Data\Attributes\Mutable;

$attr = new Attributes(['target' => '_blank']);
$attr->set('foo', 'bar');
$attr->remove('target');
$attr->toReadOnly(); // => TS\Data\Attributes\Attributes
```

Namespaced Attributes Collection
--------------------------------

[](#namespaced-attributes-collection)

```
use TS\Data\Attributes\Namespaced;

$attr = new Attributes([
  'html::target' => '_blank',
  'other::foo' => 'bar'
]);

// list used namespaces
$attr->namespaces(); // => ['html', 'other']

// extract entries with the given namespace
$attr->extract('html')->toArray(); // => ['target' => '_blank']

// keep the namespace
$attr->extract('html', Attributes::KEEP_NAMESPACE)->toArray(); // => ['html::target' => '_blank']
```

Mutable Namespaced Attributes Collection
----------------------------------------

[](#mutable-namespaced-attributes-collection)

```
use TS\Data\Attributes\MutableNamespaced;

$attr = new Attributes([
  'html::target' => '_blank',
  'other::foo' => 'bar'
]);

$attr->set('abc::foo', 'bar');
$attr->namespaces(); // => ['html', 'other', 'abc']
```

Attribute Containers
--------------------

[](#attribute-containers)

```
use TS\Data\Attributes\AttributesContainerInterface;
use TS\Data\Attributes\AttributesContainerTrait;

class My implements AttributesContainerInterface {
  use AttributesContainerTrait;
  public function __construct($attrs) {
    $this->initAttributes($attrs);
  }
}

$my = new My([
  'target' => '_blank'
]);

$my->hasAttribute('target'); // => true
$my->getAttribute('target'); // => "_blank"
$my->getAttributes(); // => AttributesInterface
```

Mutable, Namespaced and combined containers are also available:

```
use TS\Data\Attributes\Mutable\MutableContainerInterface;
use TS\Data\Attributes\Mutable\MutableContainerTrait;

class My implements MutableContainerInterface {
  use MutableContainerTrait;
  public function __construct($attrs) {
    $this->initAttributes($attrs);
  }
}

$my = new My([
  'target' => '_blank'
]);
$my->setAttribute('foo', 'bar');
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6364011a12f22cb5046056371bde6170218218c560eddfdc08b4644b7648af78?d=identicon)[timostamm](/maintainers/timostamm)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/timostamm-data-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/timostamm-data-attributes/health.svg)](https://phpackages.com/packages/timostamm-data-attributes)
```

PHPackages © 2026

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