| Recommend this page to a friend! | 
|  Download | 
| Info | Documentation |  Files |  Install with Composer |  Download | Reputation | Support forum | Blog | Links | 
| Ratings | Unique User Downloads | Download Rankings | ||||
| Not yet rated by the users | Total: 93 | All time:  9,906 This week: 47  | ||||
| Version | License | PHP version | Categories | |||
| entities 1.0.0 | The PHP License | 5 | PHP 5, Data types, Design Patterns | 
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 (9) | 
| File | Role | Description | ||
|---|---|---|---|---|
|  src (3 files) | ||||
|  tests (2 files) | ||||
|    .travis.yml | Data | Auxiliary data | ||
|    composer.json | Data | Auxiliary data | ||
|    phpunit.xml | Data | Auxiliary data | ||
|    readme.md | Doc. | Documentation | ||
|  Files (9) | / | src | 
| File | Role | Description | 
|---|---|---|
|  Entity.php | Class | Class source | 
|  EntityList.php | Class | Class source | 
|  UnexpectedEntityException.php | Class | Class source | 
|  Files (9) | / | tests | 
| File | Role | Description | 
|---|---|---|
|  EntityListTest.php | Class | Class source | 
|  EntityTest.php | Class | Class source | 
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. | 
|  Install with Composer | 
| Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
| 100% | 
 | 
 | 
| Applications that use this package | 
 If you know an application of this package, send a message to the author to add a link here.
 If you know an application of this package, send a message to the author to add a link here.