Skip to content

Instantly share code, notes, and snippets.

@fgm
Created December 19, 2017 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgm/136f68e3f30c2c2b9eb9687fd9ddcfc4 to your computer and use it in GitHub Desktop.
Save fgm/136f68e3f30c2c2b9eb9687fd9ddcfc4 to your computer and use it in GitHub Desktop.
Dump Drupal listeners, including subscribers
# Sample services file for a "rdcm" module holding the commands.
services:
rdcm.kernel_commands:
class: Drupal\rdcm\Commands\KernelCommands
arguments:
- '@event_dispatcher'
tags:
- { name: drush.command }
<?php
// Place in (module)/src/Commands
namespace Drupal\rdcm\Commands;
use Drush\Commands\DrushCommands;
use Robo\Common\OutputAwareTrait;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Yaml\Yaml;
/**
* Class KernelCommands contains generic Drupal commands.
*/
class KernelCommands extends DrushCommands {
use OutputAwareTrait;
/**
* The event_dispatcher service.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $dispatcher;
/**
* KernelCommands constructor.
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event_dispatcher service.
*/
public function __construct(EventDispatcherInterface $dispatcher) {
parent::__construct();
$this->dispatcher = $dispatcher;
}
/**
* Show listeners command.
*
* @command dispatcher:listeners
*/
public function showListeners() {
$rp = new \ReflectionProperty(get_class($this->dispatcher), 'listeners');
$rp->setAccessible(TRUE);
$listeners = $rp->getValue($this->dispatcher);
ksort($listeners);
$dump = Yaml::dump($listeners, 3, 6);
$this->output()->writeln($dump);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment