emit() public method

Convenience method for generating an event and directly adding it afterwards to persistence.
public emit ( string $eventType, array $data, string $eventClassName = Event::class ) : Event
$eventType string
$data array
$eventClassName string
return Neos\Neos\EventLog\Domain\Model\Event
コード例 #1
0
 /**
  * Record events for entity changes.
  *
  * Note: this method is registered as an Doctrine event listener in the settings of this package.
  *
  * TODO: Update/Delete of Entities
  *
  * @param OnFlushEventArgs $eventArgs
  * @return void
  * @throws Exception
  */
 public function onFlush(OnFlushEventArgs $eventArgs)
 {
     if (!$this->eventEmittingService->isEnabled()) {
         return;
     }
     $entityManager = $eventArgs->getEntityManager();
     $unitOfWork = $entityManager->getUnitOfWork();
     foreach ($unitOfWork->getScheduledEntityInsertions() as $entity) {
         $className = get_class($entity);
         if (isset($this->monitorEntitiesSetting[$className])) {
             $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className];
             if (isset($entityMonitoringConfiguration['events']['created'])) {
                 $this->initializeAccountIdentifier();
                 $data = array();
                 foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) {
                     $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, array('entity' => $entity));
                 }
                 $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['created'], $data);
                 $unitOfWork->computeChangeSet($entityManager->getClassMetadata(Event::class), $event);
             }
         }
     }
     foreach ($unitOfWork->getScheduledEntityDeletions() as $entity) {
         $className = get_class($entity);
         if (isset($this->monitorEntitiesSetting[$className])) {
             $entityMonitoringConfiguration = $this->monitorEntitiesSetting[$className];
             if (isset($entityMonitoringConfiguration['events']['deleted'])) {
                 $this->initializeAccountIdentifier();
                 $data = array();
                 foreach ($entityMonitoringConfiguration['data'] as $key => $eelExpression) {
                     $data[$key] = Utility::evaluateEelExpression($eelExpression, $this->eelEvaluator, array('entity' => $entity));
                 }
                 $event = $this->eventEmittingService->emit($entityMonitoringConfiguration['events']['deleted'], $data);
                 $unitOfWork->computeChangeSet($entityManager->getClassMetadata(Event::class), $event);
             }
         }
     }
 }