本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcherInterface::getListeners方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcherInterface::getListeners方法的具体用法?PHP EventDispatcherInterface::getListeners怎么用?PHP EventDispatcherInterface::getListeners使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\EventDispatcher\EventDispatcherInterface
的用法示例。
在下文中一共展示了EventDispatcherInterface::getListeners方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dispatch
/**
* {@inheritDoc}
*
* @param string $event The name of the Event which should be dispatched
* @param array $options The options that should get passed to the callback
*/
public function dispatch($event, $options)
{
$listeners = $this->eventDispatcher->getListeners($event);
foreach ($listeners as $listener) {
call_user_func($listener, $options);
}
}
示例2: dispatch
/**
* {@inheritdoc}
*/
public function dispatch(EventInterface $event)
{
$listeners = $this->eventDispatcher->getListeners($event->getName());
foreach ($listeners as $listener) {
if (count($listener[0]) === 2) {
$listener = $listener[0];
}
call_user_func($listener, $event);
}
}
示例3: getInternalEventListeners
/**
* returns all the listeners in the app that are listening to domain messages
*
* @return array returns array of listener details (name and callback reference) by event key
*
*/
public function getInternalEventListeners()
{
$all_listeners = $this->dispatcher->getListeners();
$domain_listeners = array();
$prefix = $this->getEventPrefix();
$prefix_length = strlen($prefix);
foreach ($all_listeners as $event_name => $listener_by_event) {
// if this event key is a domain message
if (substr($event_name, 0, $prefix_length) === $prefix) {
$domain_listeners[$event_name] = $listener_by_event;
}
}
return $domain_listeners;
}
示例4: activate
/**
* Activate cross processes tunnel.
* NB: Should be called only in child process!
* Removes all current registered listeners.
*/
public function activate()
{
foreach ($this->dispatcher->getListeners() as $event => $listeners) {
foreach ($listeners as $listener) {
$this->dispatcher->removeListener($event, $listener);
}
}
foreach ($this->events as $event) {
$this->dispatcher->addListener($event, [$this, 'onEvent']);
}
foreach ($this->sockets as $socket) {
fclose($socket);
}
fclose($this->childSocket);
}
示例5: getEventListeners
/**
* @param string $eventName
*
* @return array
*/
protected function getEventListeners($eventName)
{
$results = array();
foreach ($this->eventDispatcher->getListeners($eventName) as $listener) {
if (is_object($listener[0])) {
$results[] = get_class($listener[0]);
} elseif (is_string($listener[0])) {
$results[] = $listener[0];
} elseif ($listener instanceof \Closure) {
$results[] = '{closure}()';
} else {
$results[] = 'Unknown type!';
}
}
return $results;
}
示例6: describeEventDispatcherListeners
/**
* {@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);
}
} 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);
}
}
}
}
示例7: describeEventDispatcherListeners
/**
* {@inheritdoc}
*/
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = array())
{
$event = array_key_exists('event', $options) ? $options['event'] : null;
if (null !== $event) {
$title = sprintf('Registered Listeners for "%s" Event', $event);
} else {
$title = 'Registered Listeners Grouped by Event';
}
$options['output']->title($title);
$registeredListeners = $eventDispatcher->getListeners($event);
if (null !== $event) {
$this->renderEventListenerTable($eventDispatcher, $event, $registeredListeners, $options['output']);
} else {
ksort($registeredListeners);
foreach ($registeredListeners as $eventListened => $eventListeners) {
$options['output']->section(sprintf('"%s" event', $eventListened));
$this->renderEventListenerTable($eventDispatcher, $eventListened, $eventListeners, $options['output']);
}
}
}
示例8: getEventDispatcherListenersData
/**
* @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;
}
示例9: flushHandlers
/**
* Flush handlers.
*
* Clears all handlers.
*
* @return void
*/
public function flushHandlers()
{
foreach ($this->dispatcher->getListeners() as $eventName => $listener) {
$this->dispatcher->removeListener($eventName, $listener);
}
}
示例10: getEventDispatcherListenersDocument
/**
* @param EventDispatcherInterface $eventDispatcher
* @param string|null $event
*
* @return \DOMDocument
*/
private function getEventDispatcherListenersDocument(EventDispatcherInterface $eventDispatcher, $event = null)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($eventDispatcherXML = $dom->createElement('event-dispatcher'));
$registeredListeners = $eventDispatcher->getListeners($event);
if (null !== $event) {
foreach ($registeredListeners as $listener) {
$callableXML = $this->getCallableDocument($listener);
$eventDispatcherXML->appendChild($eventDispatcherXML->ownerDocument->importNode($callableXML->childNodes->item(0), true));
}
} else {
ksort($registeredListeners);
foreach ($registeredListeners as $eventListened => $eventListeners) {
$eventDispatcherXML->appendChild($eventXML = $dom->createElement('event'));
$eventXML->setAttribute('name', $eventListened);
foreach ($eventListeners as $eventListener) {
$callableXML = $this->getCallableDocument($eventListener);
$eventXML->appendChild($eventXML->ownerDocument->importNode($callableXML->childNodes->item(0), true));
}
}
}
return $dom;
}
示例11: describeEventDispatcherListeners
/**
* {@inheritdoc}
*/
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = array())
{
$event = array_key_exists('event', $options) ? $options['event'] : null;
$label = 'Registered listeners';
if (null !== $event) {
$label .= sprintf(' for event <info>%s</info>', $event);
} else {
$label .= ' by event';
}
$this->writeText($this->formatSection('event_dispatcher', $label) . "\n", $options);
$registeredListeners = $eventDispatcher->getListeners($event);
if (null !== $event) {
$this->writeText("\n");
$table = new Table($this->getOutput());
$table->getStyle()->setCellHeaderFormat('%s');
$table->setHeaders(array('Order', 'Callable'));
foreach ($registeredListeners as $order => $listener) {
$table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($listener)));
}
$this->renderTable($table, true);
} else {
ksort($registeredListeners);
foreach ($registeredListeners as $eventListened => $eventListeners) {
$this->writeText(sprintf("\n<info>[Event]</info> %s\n", $eventListened), $options);
$table = new Table($this->getOutput());
$table->getStyle()->setCellHeaderFormat('%s');
$table->setHeaders(array('Order', 'Callable'));
foreach ($eventListeners as $order => $eventListener) {
$table->addRow(array(sprintf('#%d', $order + 1), $this->formatCallable($eventListener)));
}
$this->renderTable($table, true);
}
}
}
示例12: describeEventDispatcherListeners
/**
* Returns an human readable description of a collection of event listeners
* in console
*
* @param OutputInterface $output
* @param EventDispatcherInterface $eventDispatcher
* @param array $options the Console input options
*/
protected function describeEventDispatcherListeners(OutputInterface $output, EventDispatcherInterface $eventDispatcher, array $options)
{
$event = array_key_exists('event', $options) ? $options['event'] : null;
$label = 'Registered listeners';
if (null !== $event) {
$label .= sprintf(' for event <info>%s</info>', $event);
} else {
$label .= ' by event';
}
$registeredListeners = $eventDispatcher->getListeners($event, true);
if (null !== $event) {
$output->writeln($label);
$output->writeln(sprintf("\n<info>[Event]</info> %s\n", $event));
$this->renderTable($output, $registeredListeners);
} else {
ksort($registeredListeners);
foreach ($registeredListeners as $eventListened => $eventListeners) {
$output->writeln(sprintf("\n<info>[Event]</info> %s\n", $eventListened));
krsort($eventListeners);
$this->renderTable($output, $eventListeners);
}
}
}
示例13: getListeners
/**
* @inheritdoc
*/
public function getListeners($eventName)
{
return $this->dispatcher->getListeners($eventName);
}
示例14: getListeners
/**
* Gets the listeners of a specific event or all listeners.
*
* @param string $eventName The name of the event.
*
* @return array The event listeners for the specified event, or all event listeners by event name
*/
public function getListeners($eventName = null)
{
return $this->realDispatcher->getListeners($eventName);
}
示例15: describeEventDispatcherListeners
/**
* {@inheritdoc}
*/
protected function describeEventDispatcherListeners(EventDispatcherInterface $eventDispatcher, array $options = array())
{
$event = array_key_exists('event', $options) ? $options['event'] : null;
$label = 'Registered listeners';
if (null !== $event) {
$label .= sprintf(' for event <info>%s</info>', $event);
} else {
$label .= ' by event';
}
$this->writeText($this->formatSection('event_dispatcher', $label) . "\n", $options);
$registeredListeners = $eventDispatcher->getListeners($event, true);
if (null !== $event) {
$this->writeText("\n");
$this->renderEventListenerTable($registeredListeners);
} else {
ksort($registeredListeners);
foreach ($registeredListeners as $eventListened => $eventListeners) {
$this->writeText(sprintf("\n<info>[Event]</info> %s\n", $eventListened), $options);
$this->renderEventListenerTable($eventListeners);
}
}
}