CRUDlex\EntityEvents

class EntityEvents

Management and execution of events.

property events

protected array

Holds the events.

shouldExecute(Entity $entity, $moment, $action)

Executes the event chain of an entity.

Parameters:
  • $entity (Entity) – the entity having the event chain to execute
  • $moment (string) – the “moment” of the event, can be either “before” or “after”
  • $action (string) – the “action” of the event, can be either “create”, “update” or “delete”
Returns:

boolean true on successful execution of the full chain or false if it broke at any point (and stopped the execution)

push($moment, $action, Closure $function)

Adds an event to fire for the given parameters. The event function must have this signature: function (Entity $entity) and has to return true or false. The events are executed one after another in the added order as long as they return “true”. The first event returning “false” will stop the process.

Parameters:
  • $moment (string) – the “moment” of the event, can be either “before” or “after”
  • $action (string) – the “action” of the event, can be either “create”, “update” or “delete”
  • $function (Closure) – the event function to be called if set
pop($moment, $action)

Removes and returns the latest event for the given parameters.

Parameters:
  • $moment (string) – the “moment” of the event, can be either “before” or “after”
  • $action (string) – the “action” of the event, can be either “create”, “update” or “delete”
Returns:

Closure|null the popped event or null if no event was available.