added helperSet to console event objects
This commit is contained in:
parent
f224102c72
commit
4edf29d04a
@ -38,13 +38,16 @@ abstract class ContainerAwareCommand extends Command implements ContainerAwareIn
|
||||
public function run(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$dispatcher = $this->getContainer()->get('event_dispatcher');
|
||||
$helperSet = $this->getHelperSet();
|
||||
|
||||
$initEvent = new ConsoleEvent($input, $output);
|
||||
$initEvent->setHelperSet($helperSet);
|
||||
$dispatcher->dispatch(ConsoleEvents::INIT, $initEvent);
|
||||
|
||||
$exitCode = parent::run($input, $output);
|
||||
|
||||
$terminateEvent = new ConsoleTerminateEvent($input, $output, $exitCode);
|
||||
$terminateEvent->setHelperSet($helperSet);
|
||||
$dispatcher->dispatch(ConsoleEvents::TERMINATE, $terminateEvent);
|
||||
|
||||
return $exitCode;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\Event;
|
||||
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
@ -26,12 +27,34 @@ class ConsoleEvent extends Event
|
||||
|
||||
private $output;
|
||||
|
||||
private $helperSet;
|
||||
|
||||
public function __construct(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->input = $input;
|
||||
$this->output = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the helper set.
|
||||
*
|
||||
* @param HelperSet $helperSet A HelperSet instance
|
||||
*/
|
||||
public function setHelperSet(HelperSet $helperSet)
|
||||
{
|
||||
$this->helperSet = $helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the helper set.
|
||||
*
|
||||
* @return HelperSet A HelperSet instance
|
||||
*/
|
||||
public function getHelperSet()
|
||||
{
|
||||
return $this->helperSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the input object
|
||||
*
|
||||
|
@ -13,8 +13,8 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Console;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\Console\Fixtures\FooCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\Console\Fixtures\SilentCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\ConsoleEvents;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
|
||||
@ -51,16 +51,6 @@ class ApplicationTest extends TestCase
|
||||
$application->doRun(new ArrayInput(array('foo')), new NullOutput());
|
||||
}
|
||||
|
||||
public function testSilentCommand()
|
||||
{
|
||||
$kernel = $this->getKernel(array(), $this->never());
|
||||
|
||||
$application = new Application($kernel);
|
||||
$application->add(new SilentCommand('chut'));
|
||||
|
||||
$application->doRun(new ArrayInput(array('chut')), new NullOutput());
|
||||
}
|
||||
|
||||
private function getKernel(array $bundles, $dispatcherExpected = null)
|
||||
{
|
||||
$kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface");
|
||||
@ -80,8 +70,19 @@ class ApplicationTest extends TestCase
|
||||
} else {
|
||||
$eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
||||
$eventDispatcher
|
||||
->expects($this->atLeastOnce())
|
||||
->method('dispatch');
|
||||
->expects($this->at(0))
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$this->equalTo(ConsoleEvents::INIT),
|
||||
$this->isInstanceOf('Symfony\Bundle\FrameworkBundle\Event\ConsoleEvent')
|
||||
);
|
||||
$eventDispatcher
|
||||
->expects($this->at(1))
|
||||
->method('dispatch')
|
||||
->with(
|
||||
$this->equalTo(ConsoleEvents::TERMINATE),
|
||||
$this->isInstanceOf('Symfony\Bundle\FrameworkBundle\Event\ConsoleTerminateEvent')
|
||||
);
|
||||
$container
|
||||
->expects($dispatcherExpected)
|
||||
->method('get')
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?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\Tests\Console\Fixtures;
|
||||
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class SilentCommand extends Command
|
||||
{
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user