/** * Check a pre-persist event for a CreateModifyTrait and update timestamps * * @param PersistEvent $event */ public function updateTimeStamps(PersistEvent $event) { $entity = $event->getEntity(); if (!$entity instanceof CreateModifyInterface) { return; } $current_time = new \DateTime(); // Force last-modified to be the current time $entity->setLastModified($current_time); // If the time created is still null, set it to the current time if (!$entity->getTimeCreated()) { $entity->setTimeCreated($current_time); } }
/** * @return \Closure */ protected function getPostPersist() { return function ($proxy, $instance, $method, $params, $returnValue, &$returnEarly) { /** @var EntityManager $instance */ $event = new PersistEvent($instance, $params['entity']); $event->setReturnValue($instance); $instance->getDispatcher()->dispatch(Event::POST_PERSIST, $event); if ($event->getAbort()) { $returnEarly = true; return $event->getReturnValue(); } return $returnValue; }; }