/** * {@inheritdoc} * * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException */ protected function dispatchEvent($action, &$entity, $isNew = false, Event $event = null) { if (!$entity instanceof User) { throw new MethodNotAllowedHttpException(array('User'), 'Entity must be of class User()'); } switch ($action) { case "pre_save": $name = UserEvents::USER_PRE_SAVE; break; case "post_save": $name = UserEvents::USER_POST_SAVE; break; case "pre_delete": $name = UserEvents::USER_PRE_DELETE; break; case "post_delete": $name = UserEvents::USER_POST_DELETE; break; default: return null; } if ($this->dispatcher->hasListeners($name)) { if (empty($event)) { $event = new UserEvent($entity, $isNew); $event->setEntityManager($this->em); } $this->dispatcher->dispatch($name, $event); return $event; } return null; }