forked from symfony/symfony
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FrameworkBundle] Add Event Dispatcher debug command
- Loading branch information
1 parent
8725243
commit ce53c8a
Showing
44 changed files
with
778 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
src/Symfony/Bundle/FrameworkBundle/Command/EventDispatcherDebugCommand.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
|
||
/** | ||
* A console command for retrieving information about event dispatcher | ||
* | ||
* @author Matthieu Auger <mail@matthieuauger.com> | ||
*/ | ||
class EventDispatcherDebugCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('debug:event-dispatcher') | ||
->setDefinition(array( | ||
new InputArgument('event', InputArgument::OPTIONAL, 'An event name (foo)'), | ||
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output description in other formats', 'txt'), | ||
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'), | ||
)) | ||
->setDescription('Displays configured listeners for an application') | ||
->setHelp(<<<EOF | ||
The <info>%command.name%</info> command displays all configured listeners: | ||
<info>php %command.full_name%</info> | ||
To get specific listeners for an event, specify its name: | ||
<info>php %command.full_name% kernel.request</info> | ||
EOF | ||
) | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws \LogicException | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
if ($event = $input->getArgument('event')) { | ||
$options = array('event' => $event); | ||
} else { | ||
$options = array(); | ||
} | ||
|
||
$dispatcher = $this->getEventDispatcher(); | ||
|
||
$helper = new DescriptorHelper(); | ||
$options['format'] = $input->getOption('format'); | ||
$options['raw_text'] = $input->getOption('raw'); | ||
$helper->describe($output, $dispatcher, $options); | ||
} | ||
|
||
/** | ||
* Loads the Event Dispatcher from the container | ||
* | ||
* @return EventDispatcherInterface | ||
*/ | ||
protected function getEventDispatcher() | ||
{ | ||
return $this->getContainer()->get('event_dispatcher'); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.