示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configManager = new ConfigurationManager($input->getOption('config-dir'));
     if (!$input->getOption('output-dir')) {
         $input->setOption('output-dir', $configManager->getSection('paths')['phpConfDir']);
     }
     $this->createDirectory($input->getOption('output-dir'));
     $outputFilePath = $input->getOption('output-dir') . DIRECTORY_SEPARATOR . $input->getOption('output-file');
     if (!is_writable(dirname($outputFilePath))) {
         throw new \RuntimeException(sprintf('Unable to write the "%s" output file', $outputFilePath));
     }
     //Create the options array to pass to ArrayToPhpConverter
     $options['connections'] = $configManager->getConnectionParametersArray();
     $options['defaultConnection'] = $configManager->getSection('runtime')['defaultConnection'];
     $options['log'] = $configManager->getSection('runtime')['log'];
     $options['profiler'] = $configManager->getConfigProperty('runtime.profiler');
     $phpConf = ArrayToPhpConverter::convert($options);
     $phpConf = "<?php\n" . $phpConf;
     if (file_exists($outputFilePath)) {
         $currentContent = file_get_contents($outputFilePath);
         if ($currentContent == $phpConf) {
             $output->writeln(sprintf('No change required in the current configuration file <info>"%s"</info>.', $outputFilePath));
         } else {
             file_put_contents($outputFilePath, $phpConf);
             $output->writeln(sprintf('Successfully updated PHP configuration in file <info>"%s"</info>.', $outputFilePath));
         }
     } else {
         file_put_contents($outputFilePath, $phpConf);
         $output->writeln(sprintf('Successfully wrote PHP configuration in file <info>"%s"</info>.', $outputFilePath));
     }
 }
    public function testGetConfigurationParametersArrayTest()
    {
        $yamlConf = <<<EOF
propel:
  database:
      connections:
          mysource:
              adapter: mysql
              classname: Propel\\Runtime\\Connection\\DebugPDO
              dsn: mysql:host=localhost;dbname=mydb
              user: root
              password:
          yoursource:
              adapter: mysql
              classname: Propel\\Runtime\\Connection\\DebugPDO
              dsn: mysql:host=localhost;dbname=yourdb
              user: root
              password:
  runtime:
      defaultConnection: mysource
      connections:
          - mysource
          - yoursource
  generator:
      defaultConnection: mysource
      connections:
          - mysource
EOF;
        $this->getFilesystem()->dumpFile('propel.yaml', $yamlConf);
        $expectedRuntime = array('mysource' => array('adapter' => 'mysql', 'classname' => 'Propel\\Runtime\\Connection\\DebugPDO', 'dsn' => 'mysql:host=localhost;dbname=mydb', 'user' => 'root', 'password' => ''), 'yoursource' => array('adapter' => 'mysql', 'classname' => 'Propel\\Runtime\\Connection\\DebugPDO', 'dsn' => 'mysql:host=localhost;dbname=yourdb', 'user' => 'root', 'password' => ''));
        $expectedGenerator = array('mysource' => array('adapter' => 'mysql', 'classname' => 'Propel\\Runtime\\Connection\\DebugPDO', 'dsn' => 'mysql:host=localhost;dbname=mydb', 'user' => 'root', 'password' => ''));
        $manager = new ConfigurationManager();
        $this->assertEquals($expectedRuntime, $manager->getConnectionParametersArray('runtime'));
        $this->assertEquals($expectedRuntime, $manager->getConnectionParametersArray());
        //default `runtime`
        $this->assertEquals($expectedGenerator, $manager->getConnectionParametersArray('generator'));
        $this->assertNull($manager->getConnectionParametersArray('bad_section'));
    }