-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ConsoleRunner similar to that in DBAL and ORM
- Loading branch information
Christian Schmidt
committed
Mar 15, 2016
1 parent
0d0ff5d
commit 443d9cf
Showing
2 changed files
with
86 additions
and
16 deletions.
There are no files selected for viewing
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
85 changes: 85 additions & 0 deletions
85
lib/Doctrine/DBAL/Migrations/Tools/Console/ConsoleRunner.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,85 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\DBAL\Migrations\Tools\Console; | ||
|
||
use Doctrine\DBAL\Migrations\Tools\Console\Command; | ||
use Doctrine\DBAL\Migrations\MigrationsVersion; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Helper\HelperSet; | ||
|
||
/** | ||
* Handles running the Console Tools inside Symfony Console context. | ||
*/ | ||
class ConsoleRunner | ||
{ | ||
/** | ||
* Runs console with the given helperset. | ||
* | ||
* @param \Symfony\Component\Console\Helper\HelperSet $helperSet | ||
* @param \Symfony\Component\Console\Command\Command[] $commands | ||
* | ||
* @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 Migrations', MigrationsVersion::VERSION()); | ||
$cli->setCatchExceptions(true); | ||
$cli->setHelperSet($helperSet); | ||
self::addCommands($cli); | ||
$cli->addCommands($commands); | ||
|
||
return $cli; | ||
} | ||
|
||
/** | ||
* @param Application $cli | ||
* | ||
* @return void | ||
*/ | ||
static public function addCommands(Application $cli) | ||
{ | ||
$cli->addCommands(array( | ||
new Command\ExecuteCommand(), | ||
new Command\GenerateCommand(), | ||
new Command\MigrateCommand(), | ||
new Command\StatusCommand(), | ||
new Command\VersionCommand(), | ||
)); | ||
|
||
if ($cli->getHelperSet()->has('em')) { | ||
$cli->add(new Command\DiffCommand()); | ||
} | ||
} | ||
} |