PHP code example of stratadox / entity-state

1. Go to this page and download the library: Download stratadox/entity-state library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stratadox / entity-state example snippets


$originalState = Extract::state()->from($identityMap);

$identityMap = $identityMap->add('id-26', new Something('foo'));

$identityMap->get(User::class, '1')->changeNameTo('Chuck Norris');

$identityMap = $identityMap->remove(Foo::class, '3');

$newState = Extract::state()->from($identityMap);

$changes = $newState->changesSince($originalState);

assert($changes->added()[0]->class() === Something::class);
assert($changes->added()[0]->id() === 'id-26');

assert($changes->altered()[0]->class() === User::class);
assert($changes->altered()[0]->id() === '1');

assert($changes->removed()[0]->class() === Foo::class);
assert($changes->removed()[0]->id() === '3');

assert($changes->altered()[0]->properties()[0]->name() === 'userName');
assert($changes->altered()[0]->properties()[0]->value() === 'Chuck Norris');

assert($changes->altered()[0]->properties()[0]->name() === 'Name:userName.name');

assert($changes->altered()[0]->properties()[0]->name() === 'Name:array:userName[0].name');

$entityState = Extract::stringifying(UuidInterface::class)->from($identityMap);