Ejemplo n.º 1
0
 protected function _getMigrationConfiguration(InputInterface $input, OutputInterface $output)
 {
     if (!$this->_configuration) {
         $outputWriter = new OutputWriter(function ($message) use($output) {
             return $output->writeln($message);
         });
         $em = $this->getHelper('em')->getEntityManager();
         if ($input->getOption('configuration')) {
             $info = pathinfo($input->getOption('configuration'));
             $class = $info['extension'] === 'xml' ? 'Doctrine\\DBAL\\Migrations\\Configuration\\XmlConfiguration' : 'Doctrine\\DBAL\\Migrations\\Configuration\\YamlConfiguration';
             $configuration = new $class($em->getConnection(), $outputWriter);
             $configuration->load($input->getOption('configuration'));
         } else {
             if (file_exists('migrations.xml')) {
                 $configuration = new XmlConfiguration($em->getConnection(), $outputWriter);
                 $configuration->load('migrations.xml');
             } else {
                 if (file_exists('migrations.yml')) {
                     $configuration = new YamlConfiguration($em->getConnection(), $outputWriter);
                     $configuration->load('migrations.yml');
                 } else {
                     $configuration = new Configuration($em->getConnection(), $outputWriter);
                 }
             }
         }
         $this->_configuration = $configuration;
     }
     return $this->_configuration;
 }
Ejemplo n.º 2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return Configuration
  */
 protected function getMigrationConfiguration(InputInterface $input, OutputInterface $output)
 {
     if (!$this->configuration) {
         $outputWriter = new OutputWriter(function ($message) use($output) {
             return $output->writeln($message);
         });
         if ($this->getApplication()->getHelperSet()->has('db')) {
             $conn = $this->getHelper('db')->getConnection();
         } else {
             if ($input->getOption('db-configuration')) {
                 if (!file_exists($input->getOption('db-configuration'))) {
                     throw new \InvalidArgumentException("The specified connection file is not a valid file.");
                 }
                 $params = (include $input->getOption('db-configuration'));
                 if (!is_array($params)) {
                     throw new \InvalidArgumentException('The connection file has to return an array with database configuration parameters.');
                 }
                 $conn = \Doctrine\DBAL\DriverManager::getConnection($params);
             } else {
                 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.');
                     }
                     $conn = \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.');
                 }
             }
         }
         if ($input->getOption('configuration')) {
             $info = pathinfo($input->getOption('configuration'));
             $class = $info['extension'] === 'xml' ? 'Doctrine\\DBAL\\Migrations\\Configuration\\XmlConfiguration' : 'Doctrine\\DBAL\\Migrations\\Configuration\\YamlConfiguration';
             $configuration = new $class($conn, $outputWriter);
             $configuration->load($input->getOption('configuration'));
         } else {
             if (file_exists('migrations.xml')) {
                 $configuration = new XmlConfiguration($conn, $outputWriter);
                 $configuration->load('migrations.xml');
             } else {
                 if (file_exists('migrations.yml')) {
                     $configuration = new YamlConfiguration($conn, $outputWriter);
                     $configuration->load('migrations.yml');
                 } else {
                     $configuration = new Configuration($conn, $outputWriter);
                 }
             }
         }
         $this->configuration = $configuration;
     }
     return $this->configuration;
 }
Ejemplo n.º 3
0
 /**
  * When any (config) command line option is passed to the migration the migrationConfiguration
  * property is set with the new generated configuration.
  * If no (config) option is passed the migrationConfiguration property is set to the value
  * of the configuration one (if any).
  * Else a new configuration is created and assigned to the migrationConfiguration property.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return Configuration
  */
 protected function getMigrationConfiguration(InputInterface $input, OutputInterface $output)
 {
     if (!$this->migrationConfiguration) {
         if ($input->getOption('configuration')) {
             $info = pathinfo($input->getOption('configuration'));
             $class = $info['extension'] === 'xml' ? 'Doctrine\\DBAL\\Migrations\\Configuration\\XmlConfiguration' : 'Doctrine\\DBAL\\Migrations\\Configuration\\YamlConfiguration';
             $configuration = new $class($this->getConnection($input), $this->getOutputWriter($output));
             $configuration->load($input->getOption('configuration'));
         } elseif (file_exists('migrations.xml')) {
             $configuration = new XmlConfiguration($this->getConnection($input), $this->getOutputWriter($output));
             $configuration->load('migrations.xml');
         } elseif (file_exists('migrations.yml')) {
             $configuration = new YamlConfiguration($this->getConnection($input), $this->getOutputWriter($output));
             $configuration->load('migrations.yml');
         } elseif (file_exists('migrations.yaml')) {
             $configuration = new YamlConfiguration($this->getConnection($input), $this->getOutputWriter($output));
             $configuration->load('migrations.yaml');
         } elseif ($this->configuration) {
             $configuration = $this->configuration;
         } else {
             $configuration = new Configuration($this->getConnection($input), $this->getOutputWriter($output));
         }
         $this->migrationConfiguration = $configuration;
     }
     return $this->migrationConfiguration;
 }
Ejemplo n.º 4
0
 public function loadConfiguration()
 {
     $config = new XmlConfiguration($this->getSqliteConnection());
     $config->load(__DIR__ . "/_files/config.xml");
     return $config;
 }