PHP Classes

PHP Entities: Create entities and collections of objects

Recommend this page to a friend!
  Info   View files Documentation   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 92 All time: 9,914 This week: 52Up
Version License PHP version Categories
entities 1.0.0The PHP License5PHP 5, Data types, Design Patterns


This package can be used to create entities and collections of objects.

It provides a base entity class that should be extended by applications to create application specify entity classes.

It takes an array of key-value pairs to assign to the entity class.

It also provides an abstract consistency check function that implementation classes should define to evaluate if the entity object has its variables set in a consistent way according to application rules.

The package also provides and entity collection class that can gather a collection of entity objects like an array.

Innovation Award
PHP Programming Innovation award nominee
August 2020
Number 3
Entities are usually objects defined by classes with variables that store values of simple objects that represent important application data structures.

This package provides an implementation of simple classes that can be used define entity objects that can provide their own consistency checking methods.

It provides also a base implementation of objects that be used to manage collections of entity objects.

Manuel Lemos
Picture of DeGraciaMathieu
  Performance   Level  
Name: DeGraciaMathieu <contact>
Classes: 17 packages by
Country: France France
Age: ???
All time rank: 295381 in France France
Week rank: 6 Up1 in France France Up
Innovation award
Innovation award
Nominee: 12x

Winner: 1x



This package provide a way to implements entities. Useful for your services or repositories.


Create your entity in dedicated class :

use Alchemistery\Entity;

class Human extends Entity
    public $name;
    public $age;

    public function isConsistent(): bool
        return ! is_null($this->name) && ! is_null($this->age);

Then instanciate a new entity like that :

$human = new Human([
    'name' => 'Bob',
    'age' => 42,

$human->name // Bob
$human->age // 42
$human->isConsistent(); // true

Create your entity list like this :

use Alchemistery\EntityList;

class People extends EntityList
    public function hasExpectedType(Entity $entity): bool
        return $entity instanceof Human::class;

    public function getYoungest(): Human
        $consistentPeople = $this->getConsistentEntities();
        uasort($consistentPeople, function ($a, $b) {
            if ($a->age === $b->age) {
                return 0;
            return ($a > $b) ? -1 : 1;

        return array_pop($consistentPeople);

Then instanciate a list like that :

$bob = new Human(['name' => 'Bob', 'age' => 12]);
$john = new Human(['name' => 'John', 'age' => 10]);

$people = new People([$bob, $john]);

$people[0]->name // Bob
$people[1]->name // John
$people->getYoungest()->name // John

  Files folder image Files  
File Role Description
Files folder imagesrc (3 files)
Files folder imagetests (2 files)
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Plain text file Entity.php Class Class source
  Plain text file EntityList.php Class Class source
  Plain text file UnexpectedEntityException.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file EntityListTest.php Class Class source
  Plain text file EntityTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,914
This week:52Up