If an EventSubscriber is added to an EventDispatcherInterface, the manager invokes {@link getSubscribedEvents} and registers the subscriber as a listener for all returned events.
Since: 2.0
Author: Guilherme Blanco (guilhermeblanco@hotmail.com)
Author: Jonathan Wage (jonwage@gmail.com)
Author: Roman Borschel (roman@code-factory.org)
Author: Bernhard Schussek (bschussek@gmail.com)
Example #1
0
 public function addSubscriber(EventSubscriberInterface $subscriber)
 {
     if ($subscriber instanceof ContainerAwareInterface) {
         $subscriber->setContainer($this->_services);
     }
     return parent::addSubscriber($subscriber);
 }
 /**
  * Show a job executions report
  *
  * @param Request $request
  * @param int     $id
  *
  * @return \Symfony\Component\HttpFoundation\Response|JsonResponse
  */
 public function showAction(Request $request, $id)
 {
     $jobExecution = $this->findOr404('Akeneo\\Component\\Batch\\Model\\JobExecution', $id);
     $this->eventDispatcher->dispatch(JobExecutionEvents::PRE_SHOW, new GenericEvent($jobExecution));
     if ('json' === $request->getRequestFormat()) {
         $archives = [];
         foreach ($this->archivist->getArchives($jobExecution) as $archiveName => $files) {
             $label = $this->translator->transchoice(sprintf('pim_import_export.download_archive.%s', $archiveName), count($files));
             $archives[$archiveName] = ['label' => ucfirst($label), 'files' => $files];
         }
         if (!$this->jobExecutionManager->checkRunningStatus($jobExecution)) {
             $this->jobExecutionManager->markAsFailed($jobExecution);
         }
         // limit the number of step execution returned to avoid memory overflow
         $context = ['limit_warnings' => 100];
         return new JsonResponse(['jobExecution' => $this->serializer->normalize($jobExecution, 'json', $context), 'hasLog' => file_exists($jobExecution->getLogFile()), 'archives' => $archives]);
     }
     return $this->render('PimEnrichBundle:JobTracker:show.html.twig', ['execution' => $jobExecution]);
 }
 /**
  * {@inheritDoc}
  */
 public function removeSubscriber(SymfonyEventSubscriberInterface $subscriber)
 {
     foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
         if (is_array($params) && is_array($params[0])) {
             foreach ($params as $listener) {
                 $this->removeListener($eventName, array($subscriber, $listener[0]));
             }
         } else {
             $this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
         }
     }
 }
Example #4
0
 public function removeSubscriber(EventSubscriberInterface $subscriber)
 {
     foreach ($subscriber->getSubscribedEvents() as $eventName => $listener) {
         $this->removeListener($eventName, [$subscriber, $listener[0]]);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $this->subscriber = new \Thrace\MediaBundle\Form\EventSubscriber\MultiFileUploadSubscriber($this->om, $this->fileManager, $this->formFactory);
     $this->subscriber->setTypeOptions($options['options']);
     $builder->addEventSubscriber($this->subscriber);
 }
 /**
  * @param EventSubscriberInterface $subscriber
  */
 public function registerActionSubscriber(EventSubscriberInterface $subscriber)
 {
     if ($subscriber instanceof LoggableReactionInterface) {
         $subscriber->setLogger($this->logger);
     }
     $this->actionDispatcher->addSubscriber($subscriber);
 }
 /**
  * Remove a subscriber
  *
  * @param EventSubscriberInterface $subscriber
  */
 public function removeSubscriber(EventSubscriberInterface $subscriber)
 {
     if ($subscriber instanceof HttpClientEventSubscriber) {
         $subscriber->attachHttpClient($this);
     }
     $this->eventDispatcher->removeSubscriber($subscriber);
 }
 /**
  * {@inheritDoc}
  */
 public function removeSubscriber(EventSubscriberInterface $subscriber)
 {
     // Copy-Pasted from EventDispatcher::removeSubscriber() to ensure removeListener() call
     foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
         if (is_array($params) && is_array($params[0])) {
             foreach ($params as $listener) {
                 $this->removeListener($eventName, array($subscriber, $listener[0]));
             }
         } else {
             $this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
         }
     }
 }