PHPackages                             rebelcode/entities - 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. rebelcode/entities

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

rebelcode/entities
==================

A lightweight library for working with class-less entities.

0323PHPCI failing

Since Mar 13Pushed 6y ago3 watchersCompare

[ Source](https://github.com/RebelCode/entities)[ Packagist](https://packagist.org/packages/rebelcode/entities)[ RSS](/packages/rebelcode-entities/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Entities
========

[](#entities)

A lightweight library for working with class-less entities, built for extendability.

This package aims to provide a robust solution for flexible entities, for when associative arrays are not enough. In this context an entity is an object that is not represented by its own class or interface.

Our primary use case for using entities was to allow 1st or 3rd party code to extend the data and behavior our objects without having to introduce extension classes and interfaces, which would bring with them other complications. On the other hand, using a hash-map-like data structure instead of formal objects means that our objects have no contract to obey, be it an interface or otherwise.

Design
------

[](#design)

Entities are hash-map structures, meaning that the data is read from entities using keys.

At its core, the system operates using **stores**, which are a simple abstraction for the storage system such as a database, filesystem, memory, remote API, etc.

```
interface StoreInterface
{
    public function get($key) : mixed;
    public function has($key) : bool;
    public function set(array $data) : StoreInterface;
}
```

The store is read using **properties**, which represent the keys of an entity. Properties are agnostic of any entity instance; instead they receive the entity instance during read and write calls. It should be noted that properties do not perform any actual writing, but instead return a "partial commit" as an associative array.

```
interface PropertyInterface
{
    public function getValue($entity) : mixed;
    public function setValue($entity, $value) : array;
}
```

A **schema** is a data-providing object that exposes a map of properties and their corresponding default values. Within this system, schemas represent the "contract". When an entity uses a schema, it MUST provide access to all of the properties given by the schema and use the default values wherever a failure may occur.

```
interface SchemaInterface
{
    public function getProperties() : array;
    public function getDefaults() : array;
}
```

And finally, **entities**. Entities expose an API similar to that of stores, but with some additions.

```
interface EntityInterface
{
    public function get($key) : mixed;
    public function set(array $data) : EntityInterface;
    public function getStore() : StoreInterface;
    public function getSchema() : SchemaInterface;
    public function export() : array;
}
```

First, the store is exposed to allow consumer code to access the raw data (ex. properties often require the store for reading).

The schema is also made available to allow consumer code to be aware of what keys may be accessed and even perform type checking. The `export()` method allows the entity to be reduced to an array for consumer code that might need to dump the entire entity (ex. REST API endpoints), without introducing iterator mechanics.

The result is a system that separates concerns quite nicely.

- Properties are reusable read-write objects that can transform raw data into the expected form and vice-versa.
- Schemas group properties together to represent an entity type, agnostic of the store.
- Stores provide a simple abstraction API for any form of storage.
- Entities are agnostic of their schema or store implementations.

With this design, schemas replace the traditional class and interface combo for object contracts. Because they have no awareness of the entity's store, the same schema can be used in conjunction with any kind of storage system; database, remote web API, file system or in-memory array.

Example Usage
-------------

[](#example-usage)

```
class UserSchema implements SchemaInterface {
    public function getProperties() {
        return [
            'id' => new SimpleProperty('user_id'),
            'username' => new SimpleProperty('user_name'),
            'fullname' => new ConcatProperty(['first_name', 'last_name']),
        ];
    }

    public function getDefaults() {
        return [
            'id' => 0,
            'username' => '',
            'fullname' => '',
        ];
    }
}

$schema = new UserSchema();

// FROM A DATABASE
$store = $someDb->getUser(123);
$entity = new Entity($schema, $store);

// FROM AN ARRAY
$store = new ArrayStore([
    'user_id' => 123,
    'user_name' => 'foo',
    'first_name' => 'Foo',
    'last_name' => 'Bar',
]);
$entity = new Entity($schema, $store);
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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/a8036caaa483e3f8a21d0083284bd508f5ada08ad45b790b5075ecff49f09b6b?d=identicon)[rebelcode](/maintainers/rebelcode)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/rebelcode-entities/health.svg)

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

###  Alternatives

[guava/filament-icon-picker

A filament plugin that adds an icon picker field.

161531.9k25](/packages/guava-filament-icon-picker)[mdmsoft/yii2-gii

Yii2 custom generator for gii

1335.4k1](/packages/mdmsoft-yii2-gii)

PHPackages © 2026

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