Trigger a BackBee\Event\Event depending on the entity and event name.

@access protected

@param string    $eventName The doctrine event name
@param Object    $entity    The entity instance
@param EventArgs $eventArgs The doctrine event arguments
433466
protected function _triggerEvent($eventName, $entity, $eventArgs)
    {
        if (null === $this->_application) {
            return;
        }

        $dispatcher = $this->_application->getEventDispatcher();
        if (null !== $dispatcher) {
            $dispatcher->triggerEvent($eventName, $entity, $eventArgs);
        }
    }
1209914
protected function _trigger($eventName, Subject $data = null)
    {
        return $this->_crud()->trigger($eventName, $data);
    }
1120054
public function postLoad(EventArgs $eventArgs)
    {
        if (method_exists($eventArgs, 'getEntity')) {
            $this->_triggerEvent(Events::postLoad, $eventArgs->getEntity(), $eventArgs);
        }
    }
139036
public function postLoad(LifecycleEventArgs $eventArgs)
    {
        $this->loadTranslation(
            $eventArgs->getEntityManager(),
            $eventArgs->getEntity(),
            $this->getLocale()
        );
    }
915361
public function dispatch($event/*, string $eventName = null*/)
    {
        $eventName = 1 < \func_num_args() ? \func_get_arg(1) : null;

        if (\is_object($event)) {
            $eventName = $eventName ?? \get_class($event);
        } else {
            @trigger_error(sprintf('Calling the "%s::dispatch()" method with the event name as first argument is deprecated since Symfony 4.3, pass it second and provide the event object first instead.', EventDispatcherInterface::class), E_USER_DEPRECATED);
            $swap = $event;
            $event = $eventName ?? new Event();
            $eventName = $swap;

            if (!$event instanceof Event) {
                throw new \TypeError(sprintf('Argument 1 passed to "%s::dispatch()" must be an instance of %s, %s given.', EventDispatcherInterface::class, Event::class, \is_object($event) ? \get_class($event) : \gettype($event)));
            }
        }

        $listeners = $this->getListeners($eventName);
        $stoppable = $event instanceof Event || $event instanceof ContractsEvent || $event instanceof StoppableEventInterface;

        foreach ($listeners as $listener) {
            if ($stoppable && $event->isPropagationStopped()) {
                break;
            }
            $listener($event, $eventName, $this);
        }

        return $event;
    }
614892
public function trigger($eventName, $target = null)
    {
        $event = $this->createEvent($eventName);
        $event->setTarget($target);
        $this->triggerHandlers($event);
    }
994625
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $dm  = $eventArgs->getDocumentManager();
        $uow = $dm->getUnitOfWork();
        
        $filter = function ($element) {
            return $element instanceof ApplicationInterface
                   && $element->getPermissions()->hasChanged();
        };
        
        $inserts = array_filter($uow->getScheduledDocumentInsertions(), $filter);
        $updates = array_filter($uow->getScheduledDocumentUpdates(), $filter);
        
        foreach (array($inserts, $updates) as $isUpdate => $documents) {
            foreach ($documents as $document) { /* @var \Applications\Entity\Application $document */
                $permissions = $document->getPermissions();
               
                foreach ($document->getAttachments() as $attachment) {  /* @var \Applications\Entity\Attachment $attachment */
                    $attachment->getPermissions()
                               ->clear()
                               ->inherit($permissions);
                    if ($isUpdate) {
                        $uow->computeChangeSet(
                            $dm->getClassMetadata(get_class($attachment)),
                            $attachment
                        );
                    }
                }
                
                if ($image = $document->getContact()->getImage()) {
                    $image->getPermissions()
                          ->clear()
                          ->inherit($permissions);
                    if ($isUpdate) {
                        $uow->computeChangeSet(
                            $dm->getClassMetadata(get_class($image)),
                            $image
                        );
                    }
                }
            }
        }
    }
842467
public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $this->em = $eventArgs->getEntityManager();
        $this->quoteStrategy = $this->em->getConfiguration()->getQuoteStrategy();
        $this->conn = $this->em->getConnection();
        $this->uow = $this->em->getUnitOfWork();
        $this->platform = $this->conn->getDatabasePlatform();
        $this->revisionId = null; // reset revision

        $processedEntities = [];

        foreach ($this->uow->getScheduledEntityDeletions() as $entity) {
            //doctrine is fine deleting elements multiple times. We are not.
            $hash = $this->getHash($entity);

            if (\in_array($hash, $processedEntities, true)) {
                continue;
            }

            $processedEntities[] = $hash;

            $class = $this->em->getClassMetadata(\get_class($entity));
            if (!$this->metadataFactory->isAudited($class->name)) {
                continue;
            }

            $entityData = array_merge($this->getOriginalEntityData($entity), $this->uow->getEntityIdentifier($entity));
            $this->saveRevisionEntityData($class, $entityData, 'DEL');
        }

        foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
            if (!$this->metadataFactory->isAudited(\get_class($entity))) {
                continue;
            }

            $this->extraUpdates[spl_object_hash($entity)] = $entity;
        }

        foreach ($this->uow->getScheduledEntityUpdates() as $entity) {
            if (!$this->metadataFactory->isAudited(\get_class($entity))) {
                continue;
            }

            $this->extraUpdates[spl_object_hash($entity)] = $entity;
        }
    }
884849
public function bind($eventName, $callback, $mode = EventsHandlerInterface::BINDING_MODE_LAST)
    {
        if ($eventsHandler = $this->getEventsHandler()) {
            $eventsHandler->bind($eventName, $callback, $mode);
        }
    }
1079715
public function beforeSave(Event $event, Entity $entity) {
		if (isset($entity['name'])) {
			$entity['name'] = ucwords($entity['name']);
		}

		return true;
	}
454018
public function dispatchEvent(EventArgs $eventArgs)
    {
        if ($eventArgs->sender === null) {
            $eventArgs->sender = $this;
        }
        // 标记开始传播
        $eventArgs->propagationStopped = false;
        $eventClass = get_class($eventArgs);
        if (isset($this->eventListenerMap[$eventClass])) {
            $eventHandlers = $this->eventListenerMap[$eventClass];
            // 依次调用注册的事件处理器
            foreach ($eventHandlers as $handler) {
                if ($eventArgs->propagationStopped) {
                    return;
                }
                call_user_func($handler, $eventArgs);
            }
        }
    }
506318
public function dispatch($eventName, $params)
    {
        if (isset($this->enabledProviderListeners[$eventName])) {
            foreach ($this->enabledProviderListeners[$eventName] as $callback) {
                call_user_func_array($callback, $params);
            }
        }
    }
984975
public function prePersist(LifecycleEventArgs $eventArgs)
	{
		$entity = $eventArgs->getEntity();

		if ($entity instanceof TimestampableInterface) {
			$now = new \DateTime();
			$entity->setModificationTime($now);
			$entity->setCreationTime($now);
		}
	}
897940
protected function triggerMethod($eventName, Event $event)
    {
        $method = sprintf('on%s', Container::camelize(str_replace('.', '_', $eventName)));

        if(is_callable([$this, $method])) {
            call_user_func_array([$this, $method], [$event]);
        }

        if($event->isPropagationStopped()){
            return $event;
        }

        $this->getDispatcher()->dispatch($eventName, $event);

        return $event;
    }
935595
public function trigger($eventName, array $params = []) {
        $event = clone $this->event;
        $event->setName($eventName);

        // Add optional extra arguments
        foreach ($params as $key => $value) {
            $event->setArgument($key, $value);
        }

        // Fetch current user
        $user = $event->getRequest()->getUser();

        // Trigger all listeners for this event and pass in the event instance
        foreach ($this->getListenersForEvent($eventName) as $listener) {
            $event->setArgument('handler', $listener['handler']);
            $callback = $this->getHandlerInstance($listener['handler']);

            if ($callback instanceof ListenerInterface) {
                $callback = [$callback, $listener['method']];
            }

            $users = $listener['users'];

            if (!$this->triggersFor($user, $users)) {
                continue;
            }

            $callback($event);

            if ($event->isPropagationStopped()) {
                break;
            }
        }

        return $this;
    }
158545
public static function create( $eventName, $eventArgs = null ) {
			
			if ( !is_string( $eventName ) ) {
				throw new \browserfs\Exception('Invalid argument $eventName: string expected!');
			}
			
			if ( null !== $eventArgs && !is_array( $eventArgs ) ) {
				throw new \browserfs\Exception('Invalid argument $eventArgs: any[] | null expected');
			}

			return new static( $eventName, null === $eventArgs ? [] : array_values( $eventArgs ) );
		}
1231522
public function onFlush(OnFlushEventArgs $eventArgs)
	{
		$em = $eventArgs->getEntityManager();
		$uow = $em->getUnitOfWork();

		foreach ($uow->getScheduledEntityUpdates() as $entity) {
			if ($entity instanceof TimestampableInterface) {
				$entity->setModificationTime();
				$className = get_class($entity);
				$class = $em->getClassMetadata($className);
				$uow->recomputeSingleEntityChangeSet($class, $entity);
			}
		}
	}