cycle/entity-behavior package is a collection of attributes that add behaviors to Cycle ORM entities. The package
also provides a simple API to create custom behavior attributes.
The package provides extended command generator (
Cycle\ORM\Entity\Behavior\EventDrivenCommandGenerator), that will
fire events on create, update and delete entity. The generator dispatch several events, allowing you to hook into the
following moments in a entity's lifecycle: creating, created, updating, updated,deleting and deleted.
Note: Embedded entities do not support behaviors at the moment.
The package is available via composer and can be installed using the following command:
composer require cycle/entity-behavior
After installation the package you need to create
Cycle\ORM\ORM object with
\Cycle\ORM\Entity\Behavior\EventDrivenCommandGenerator generator object as third (
use Cycle\ORM\ORM; use Cycle\ORM\Entity\Behavior\EventDrivenCommandGenerator; // Application container (PSR-11 compatible). // https://www.php-fig.org/psr/psr-11/ $container = new Container(); $commandGenerator = new EventDrivenCommandGenerator($schema, $container); $orm = new ORM( factory: $factory, schema: $schema, commandGenerator: $commandGenerator );
That's it. Now you can use all benefits of this package.