public static function events(EventEmitter $emitter) { $emitter->on("beforeInsert", function (EntityInterface $entity, MapperInterface $mapper) { $entity->uid = Base62::encode(random_bytes(9)); }); $emitter->on("beforeUpdate", function (EntityInterface $entity, MapperInterface $mapper) { $entity->updated_at = new \DateTime(); }); }
public static function events(EventEmitter $eventEmitter) { // This is done only to allow events to be set dynamically in a very // specific way for testing purposes. You probably don't want to do // this in your code... foreach (static::$events as $eventName => $methods) { $eventEmitter->on($eventName, function ($entity, $mapper) use($methods) { foreach ($methods as $method) { $entity->{$method}(); } }); } }
public static function events(EventEmitter $eventEmitter) { $eventEmitter->on('beforeInsert', function ($entity, $mapper) { $entity->token = uniqid(); }); $eventEmitter->on('afterInsert', function ($entity, $mapper) { $mapper = test_spot_mapper('SpotTest\\Entity\\Event\\Search'); $result = $mapper->create(['event_id' => $entity->id, 'body' => $entity->title . ' ' . $entity->description]); if (!$result) { throw new \Spot\Exception("Event search index entity failed to save!"); } }); }