Merge pull request #1069 from anho/reuse-console-app
added method to be able to reuse the console application
This commit is contained in:
commit
723529ffff
@ -507,3 +507,22 @@ defined ones) is possible through the command:
|
||||
new \MyProject\Tools\Console\Commands\AnotherCommand(),
|
||||
new \MyProject\Tools\Console\Commands\OneMoreCommand(),
|
||||
));
|
||||
|
||||
|
||||
Re-use console application
|
||||
--------------------------
|
||||
|
||||
You are also able to retrieve and re-use the default console application.
|
||||
Just call ``ConsoleRunner::createApplication(...)`` with an appropriate
|
||||
HelperSet, like it is described in the configuration section.
|
||||
|
||||
.. code-block:: php
|
||||
|
||||
<?php
|
||||
|
||||
// Retrieve default console application
|
||||
$cli = ConsoleRunner::createApplication($helperSet);
|
||||
|
||||
// Runs console application
|
||||
$cli->run();
|
||||
|
||||
|
@ -55,13 +55,29 @@ class ConsoleRunner
|
||||
* @return void
|
||||
*/
|
||||
static public function run(HelperSet $helperSet, $commands = array())
|
||||
{
|
||||
$cli = self::createApplication($helperSet, $commands);
|
||||
$cli->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a console application with the given helperset and
|
||||
* optional commands.
|
||||
*
|
||||
* @param \Symfony\Component\Console\Helper\HelperSet $helperSet
|
||||
* @param array $commands
|
||||
*
|
||||
* @return \Symfony\Component\Console\Application
|
||||
*/
|
||||
static public function createApplication(HelperSet $helperSet, $commands = array())
|
||||
{
|
||||
$cli = new Application('Doctrine Command Line Interface', Version::VERSION);
|
||||
$cli->setCatchExceptions(true);
|
||||
$cli->setHelperSet($helperSet);
|
||||
self::addCommands($cli);
|
||||
$cli->addCommands($commands);
|
||||
$cli->run();
|
||||
|
||||
return $cli;
|
||||
}
|
||||
|
||||
/**
|
||||
|
26
tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php
Normal file
26
tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Tools\Console;
|
||||
|
||||
use Doctrine\ORM\Tools\Console\ConsoleRunner;
|
||||
use Doctrine\ORM\Version;
|
||||
use Doctrine\Tests\DoctrineTestCase;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
|
||||
/**
|
||||
* @group DDC-3186
|
||||
*
|
||||
* @covers \Doctrine\ORM\Tools\Console\ConsoleRunner
|
||||
*/
|
||||
class ConsoleRunnerTest extends DoctrineTestCase
|
||||
{
|
||||
public function testCreateApplication()
|
||||
{
|
||||
$helperSet = new HelperSet();
|
||||
$app = ConsoleRunner::createApplication($helperSet);
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Console\Application', $app);
|
||||
$this->assertSame($helperSet, $app->getHelperSet());
|
||||
$this->assertEquals(Version::VERSION, $app->getVersion());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user