Created
December 19, 2017 14:34
-
-
Save fgm/136f68e3f30c2c2b9eb9687fd9ddcfc4 to your computer and use it in GitHub Desktop.
Dump Drupal listeners, including subscribers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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