Пример #1
0
 /**
  * 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
  */
 public static function createApplication(HelperSet $helperSet, $commands = [])
 {
     $cli = new Application('Doctrine Migrations', MigrationsVersion::VERSION());
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     self::addCommands($cli);
     $cli->addCommands($commands);
     return $cli;
 }
Пример #2
0
 public function testVersionNumber()
 {
     $class = new \ReflectionClass($this->MigrationVersionClass);
     $property = $class->getProperty('version');
     $property->setAccessible(true);
     $versionNumber = $property->getValue(new MigrationsVersion());
     $this->assertRegExp('/^v[0-9]{1,}\\.[0-9]{1,}\\.[0-9]{1,}(-([a-z]){1,}[0-9]{1,}){0,1}$/', $versionNumber);
     $this->assertEquals($versionNumber, MigrationsVersion::VERSION());
 }
Пример #3
0
 protected function setUp()
 {
     if (file_exists(__DIR__ . '/_files/migrations.db')) {
         @unlink(__DIR__ . '/_files/migrations.db');
     }
     foreach ($this->globVersions() as $file) {
         @unlink($file);
     }
     $this->conn = $this->getSqliteConnection();
     $this->application = new Application('Doctrine Migrations Test', MigrationsVersion::VERSION());
     $this->application->setCatchExceptions(false);
     $this->application->setAutoExit(false);
     $this->application->getHelperSet()->set(new ConnectionHelper($this->conn), 'connection');
     $this->application->addCommands(array(new MigrationCommands\ExecuteCommand(), new MigrationCommands\GenerateCommand(), new MigrationCommands\LatestCommand(), new MigrationCommands\MigrateCommand(), new MigrationCommands\StatusCommand(), new MigrationCommands\VersionCommand()));
 }
Пример #4
0
<?php

/*
 * This file is part of prooph/proophessor.
 * (c) 2014-2015 prooph software GmbH <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * Date: 9/5/15 - 10:10 PM
 */
/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));
// Setup autoloading
require 'vendor/autoload.php';
$container = (require 'config/container.php');
$cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', \Doctrine\DBAL\Migrations\MigrationsVersion::VERSION());
$helperSet = new \Symfony\Component\Console\Helper\HelperSet();
$helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
$helperSet->set(new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($container->get('doctrine.connection.default')), 'connection');
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
$cli->addCommands(array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()));
$cli->run();
Пример #5
0
// Support for using the Doctrine ORM convention of providing a `cli-config.php` file.
$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';
$helperSet = null;
if (file_exists($configFile)) {
    if (!is_readable($configFile)) {
        trigger_error('Configuration file [' . $configFile . '] does not have read permission.', E_ERROR);
    }
    require $configFile;
    foreach ($GLOBALS as $helperSetCandidate) {
        if ($helperSetCandidate instanceof \Symfony\Component\Console\Helper\HelperSet) {
            $helperSet = $helperSetCandidate;
            break;
        }
    }
}
$helperSet = $helperSet ?: new \Symfony\Component\Console\Helper\HelperSet();
if (class_exists('\\Symfony\\Component\\Console\\Helper\\QuestionHelper')) {
    $helperSet->set(new \Symfony\Component\Console\Helper\QuestionHelper(), 'question');
} else {
    $helperSet->set(new \Symfony\Component\Console\Helper\DialogHelper(), 'dialog');
}
$cli = new \Symfony\Component\Console\Application('Doctrine Migrations', \Doctrine\DBAL\Migrations\MigrationsVersion::VERSION());
$cli->setCatchExceptions(true);
$cli->setHelperSet($helperSet);
$cli->addCommands(array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand()));
if ($helperSet->has('em')) {
    $cli->add(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand());
}
$input = file_exists('migrations-input.php') ? include 'migrations-input.php' : null;
$output = file_exists('migrations-output.php') ? include 'migrations-output.php' : null;
$cli->run($input, $output);
Пример #6
0
use Doctrine\DBAL\Migrations\MigrationsVersion;
use Doctrine\DBAL\Migrations\Tools\Console\Command as MigrationsCommand;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
require 'vendor/autoload.php';
// Create the database connection and set up bit for boolean mapping
if (file_exists('migrations-db.php')) {
    $params = (include 'migrations-db.php');
    if (!is_array($params)) {
        throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
    }
    $connection = \Doctrine\DBAL\DriverManager::getConnection($params);
} else {
    throw new \InvalidArgumentException('You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrations.');
}
// Instantiate console application
$cli = new Console\Application('Doctrine Migrations', MigrationsVersion::VERSION());
$cli->setCatchExceptions(true);
$helperSet = new Console\Helper\HelperSet();
$helperSet->set(new Console\Helper\DialogHelper(), 'dialog');
$helperSet->set(new ConnectionHelper($connection), 'connection');
$cli->setHelperSet($helperSet);
// Add Migrations commands
$commands = array();
$commands[] = new MigrationsCommand\ExecuteCommand();
$commands[] = new MigrationsCommand\GenerateCommand();
$commands[] = new MigrationsCommand\LatestCommand();
$commands[] = new MigrationsCommand\MigrateCommand();
$commands[] = new MigrationsCommand\StatusCommand();
$commands[] = new MigrationsCommand\VersionCommand();
// remove the "migrations:" prefix on each command name
foreach ($commands as $command) {