Revision: Fri, 31 May 2024 16:10:42 GMT

Entity behaviors

The 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 passing \Cycle\ORM\Entity\Behavior\EventDrivenCommandGenerator generator object as third (commandGenerator) argument.


use Cycle\ORM\ORM;
use Cycle\ORM\Entity\Behavior\EventDrivenCommandGenerator;

// Application container (PSR-11 compatible).
$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.

Available behaviors

Edit this page