PHPackages                             rkgrep/attributable - 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. rkgrep/attributable

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

rkgrep/attributable
===================

Fast an elegant way to make dynamic objects

v1.1(11y ago)337MITPHPPHP &gt;=5.4.0

Since May 8Pushed 10y ago1 watchersCompare

[ Source](https://github.com/rkgrep/attributable)[ Packagist](https://packagist.org/packages/rkgrep/attributable)[ RSS](/packages/rkgrep-attributable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Attributable
------------

[](#attributable)

[![Build Status](https://camo.githubusercontent.com/2ed146f403efd90f6fa37f75b7fa7c6925d6f7f750099842fc3961cce7a42496/68747470733a2f2f7472617669732d63692e6f72672f726b677265702f617474726962757461626c652e737667)](https://travis-ci.org/rkgrep/attributable)[![Latest Stable Version](https://camo.githubusercontent.com/ff3735579ab64835f861e6fa51ca7c62876bc039015a2d9fcc61e7595b50a0e6/68747470733a2f2f706f7365722e707567782e6f72672f726b677265702f617474726962757461626c652f762f737461626c652e737667)](https://packagist.org/packages/rkgrep/attributable)[![Latest Unstable Version](https://camo.githubusercontent.com/2c3d9c17a950972d35555e86e88357748f1ca7828868fd18b12e81d388fa7ba5/68747470733a2f2f706f7365722e707567782e6f72672f726b677265702f617474726962757461626c652f762f756e737461626c652e737667)](https://packagist.org/packages/rkgrep/attributable)[![License](https://camo.githubusercontent.com/f0f779b6ba0b7ae166cc1a9e70df0e97532031f1069280962c23a740dbdc6d1f/68747470733a2f2f706f7365722e707567782e6f72672f726b677265702f617474726962757461626c652f6c6963656e73652e737667)](https://packagist.org/packages/rkgrep/attributable)[![SensioLabsInsight](https://camo.githubusercontent.com/e1de49f89928a0179a5b5e502da9a9a49e16f1af36d5613c18bdd072e3889ed7/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65343563653130612d346334352d343865342d383531612d3964393534333666366535382f6d696e692e706e67)](https://insight.sensiolabs.com/projects/e45ce10a-4c45-48e4-851a-9d95436f6e58)

> **Note:** Original idea by Taylor Otwell in [Laravel Framework](https://github.com/laravel/framework).

The package includes traits which allow fluent and elegant way to work with internal object property arrays.

Installation
------------

[](#installation)

Install the package with composer.

```
composer require rkgrep/attributable

```

Apply the trait to any class you need.

```
class Foo {

    use rkgrep\Attributable;

}
```

```
class Bar {

    use rkgrep\Fillable;

}
```

Usage
-----

[](#usage)

### Attributable trait

[](#attributable-trait)

`Attributable` provides different access and assignment ways.

Assign internal variables via property or method call

```
$foo->var1 = 1;
$foo->var2(2);
```

Access variables via property

```
echo $foo->var1;
echo $foo->var2;
```

Provide fallback value via `get` method

```
$foo->get('var4', 'fallback');
$foo->get('var5', function() { return 'closure result'; });
```

Get all internal variables via `getAttributes` method

```
$all = $foo->getAttributes();
```

Method call without arguments assigns `true`

```
$foo->viewable();
true == $foo->viewable;
```

Chain methods for fast assignment

```
$user->first_name('John')->last_name('Doe')->admin();
```

### Fillable trait

[](#fillable-trait)

`Fillable` provides chaining assignment of variables or groups of variables.

Mass assign atributes with `fill` method

```
$user->fill(['name' => 'Admin', 'email' => 'admin@example.com']);
```

Overwrite or reassign control via second parameter

```
$user->fill(['name' => 'John Doe']); // Name changed, email remains untouched
$user->fill(['email' => 'other@example.com'], false); // Disabled merging - old values are dropped
```

Fill specific properties with `with` method

```
$user->with('password', md5('password'));
```

Prevent overriding with third parameter

```
$user->with('password', '', false); // Password remains untouched
```

Assign multiple variables

```
$user->with(['friends' => ['Mike', 'Dave'], 'girlfriend' => 'Jane']);
$user->with(['siblings' => [], 'girlfriend' => 'Mary'], null, false); // Overriding disabled - only siblings are touched
```

Chain method calls

```
$post->fill(['title' => 'Lorem Ipsum'])->with('views', 5)->with('likes', 3);
```

Interfaces
----------

[](#interfaces)

Any class with `Attributable` trait applied implements `ArrayAccess` and `JsonSerializable`. If you use *illuminate/support* package you can also apply `Arrayable` and `Jsonable` interfaces.

```
class Bar implements ArrayAccess, JsonSerializable, Arrayable, Jsonable {

    use rkgrep\Attributable;

}

$bar = new Bar();
$bar->value('test');

$arrayValue = $bar['value'];
$bar['value'] = 'new';
$json = json_encode($bar); // returns '{"value": "new"}'

$array = $bar->toArray();
$json = $bar->toJson();
```

License
-------

[](#license)

**Attributable** package is open-sourced package licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Every ~3 days

Total

3

Last Release

4023d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/63663c27f1d7e87cbd4472c0d3e0920bdb1cc85e8a1ad7f8d875171ce6e46ca9?d=identicon)[rkgrep](/maintainers/rkgrep)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rkgrep-attributable/health.svg)

```
[![Health](https://phpackages.com/badges/rkgrep-attributable/health.svg)](https://phpackages.com/packages/rkgrep-attributable)
```

###  Alternatives

[mageplaza/module-google-maps

Magento 2 Google Maps Extension

1127.0k](/packages/mageplaza-module-google-maps)[stepanenko3/nova-markdown

Nova Markdown advanced field

1028.7k](/packages/stepanenko3-nova-markdown)

PHPackages © 2026

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