Пример #1
0
 /**
  * @param array $array
  */
 private function renderEventListenerTable(EventDispatcherInterface $eventDispatcher, $event, array $eventListeners, SymfonyStyle $io)
 {
     $tableHeaders = array('Order', 'Callable', 'Priority');
     $tableRows = array();
     $order = 1;
     foreach ($eventListeners as $order => $listener) {
         $tableRows[] = array(sprintf('#%d', $order + 1), $this->formatCallable($listener), $eventDispatcher->getListenerPriority($event, $listener));
     }
     $io->table($tableHeaders, $tableRows);
 }
Пример #2
0
 /**
  * @param EventDispatcherInterface $eventDispatcher
  * @param string|null              $event
  *
  * @return array
  */
 private function getEventDispatcherListenersData(EventDispatcherInterface $eventDispatcher, $event = null)
 {
     $data = array();
     $registeredListeners = $eventDispatcher->getListeners($event);
     if (null !== $event) {
         foreach ($registeredListeners as $listener) {
             $l = $this->getCallableData($listener);
             $l['priority'] = $eventDispatcher->getListenerPriority($event, $listener);
             $data[] = $l;
         }
     } else {
         ksort($registeredListeners);
         foreach ($registeredListeners as $eventListened => $eventListeners) {
             foreach ($eventListeners as $eventListener) {
                 $l = $this->getCallableData($eventListener);
                 $l['priority'] = $eventDispatcher->getListenerPriority($eventListened, $eventListener);
                 $data[$eventListened][] = $l;
             }
         }
     }
     return $data;
 }
Пример #3
0
 /**
  * Gets the listener priority for a specific event.
  *
  * Returns null if the event or the listener does not exist.
  *
  * @param string   $eventName The name of the event
  * @param callable $listener  The listener
  *
  * @return int|null The event listener priority
  */
 public function getListenerPriority($eventName, $listener)
 {
     return $this->symfonyDispatcher->getListenerPriority($eventName, $listener);
 }
 /**
  * {@inheritdoc}
  */
 protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = array())
 {
     $event = array_key_exists('event', $options) ? $options['event'] : null;
     $title = 'Registered listeners';
     if (null !== $event) {
         $title .= sprintf(' for event `%s` ordered by descending priority', $event);
     }
     $this->write(sprintf('# %s', $title) . "\n");
     $registeredListeners = $eventDispatcher->getListeners($event);
     if (null !== $event) {
         foreach ($registeredListeners as $order => $listener) {
             $this->write("\n" . sprintf('## Listener %d', $order + 1) . "\n");
             $this->describeCallable($listener);
             $this->write(sprintf('- Priority: `%d`', $eventDispatcher->getListenerPriority($event, $listener)) . "\n");
         }
     } else {
         ksort($registeredListeners);
         foreach ($registeredListeners as $eventListened => $eventListeners) {
             $this->write("\n" . sprintf('## %s', $eventListened) . "\n");
             foreach ($eventListeners as $order => $eventListener) {
                 $this->write("\n" . sprintf('### Listener %d', $order + 1) . "\n");
                 $this->describeCallable($eventListener);
                 $this->write(sprintf('- Priority: `%d`', $eventDispatcher->getListenerPriority($eventListened, $eventListener)) . "\n");
             }
         }
     }
 }
Пример #5
0
 /**
  *
  * @param \DOMElement $element
  * @param array $eventListeners
  */
 private function appendEventListenerDocument(EventDispatcherInterface $eventDispatcher, $event, \DOMElement $element, array $eventListeners)
 {
     foreach ($eventListeners as $listener) {
         $callableXML = $this->getCallableDocument($listener);
         $callableXML->childNodes->item(0)->setAttribute('priority', $eventDispatcher->getListenerPriority($event, $listener));
         $element->appendChild($element->ownerDocument->importNode($callableXML->childNodes->item(0), true));
     }
 }