/** * Handle event * @param NotificationEvent $event * @throws \Exception */ public function handle(NotificationEvent $event) { if (null === $this->container->get('security.context')->getToken()) { return; } $entity = $event->getEntity(); $entityClass = ClassUtils::getClass($entity); $config = $this->getConfig($entityClass); /*Check if entity has config, if not we do not handle*/ if ($config) { $request = $this->container->get('request'); $route = $request->attributes->get('_controller'); /*Find matching rules on entity configuration*/ $matchingRules = array(); foreach ($config['rules'] as $rule) { if ($event->getName() === $rule['event'] && ($rule['route'] === '*' || $rule['route'] !== '*' && $rule['route'] === $route)) { $matchingRules[] = $rule; } } /* If more than one rule, * we remove rules which has no route specified to get more specific rule */ if (count($matchingRules) > 1) { foreach ($matchingRules as $index => $mrule) { if ($mrule['route'] === '*') { unset($matchingRules[$index]); } } if (count($matchingRules) > 1) { throw new \Exception('There is more than one notification rule matching for entity ' . $entityClass); } } if (count($matchingRules) > 0) { $rule = $matchingRules[0]; $this->factory->create($event, $rule); } } }
/** * @param $entity * @param array $entityChangeSet * @param array $parameters */ public function __construct($entity, array $entityChangeSet, array $parameters = array()) { parent::__construct($entity, $parameters); $this->entityChangeSet = $entityChangeSet; }