/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $inputFilePath = $input->getOption('input-dir') . DIRECTORY_SEPARATOR . $input->getOption('input-file'); if (!file_exists($inputFilePath)) { throw new \RuntimeException(sprintf('Unable to find the "%s" configuration file', $inputFilePath)); } $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)); } $stringConf = file_get_contents($inputFilePath); $arrayConf = XmlToArrayConverter::convert($stringConf); $phpConf = ArrayToPhpConverter::convert($arrayConf); $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)); } }
/** * {@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 testConvertConvertsCompleteConfiguration() { $conf = array('log' => array('defaultLogger' => array('type' => 'stream', 'level' => '300', 'path' => '/var/log/propel.log')), 'connections' => array('bookstore' => array('adapter' => 'mysql', 'classname' => '\\Propel\\Runtime\\Connection\\DebugPDO', 'dsn' => 'mysql:host=127.0.0.1;dbname=test', 'user' => 'root', 'password' => '', 'options' => array('ATTR_PERSISTENT' => false), 'attributes' => array('ATTR_EMULATE_PREPARES' => true), 'settings' => array('charset' => 'utf8')), 'bookstore-cms' => array('adapter' => 'mysql', 'dsn' => 'mysql:host=localhost;dbname=bookstore', 'slaves' => array(array('dsn' => 'mysql:host=slave-server1; dbname=bookstore'), array('dsn' => 'mysql:host=slave-server2; dbname=bookstore')))), 'defaultConnection' => 'bookstore'); $expected = <<<'EOF' $serviceContainer = \Propel\Runtime\Propel::getServiceContainer(); $serviceContainer->checkVersion('2.0.0-dev'); $serviceContainer->setAdapterClass('bookstore', 'mysql'); $manager = new \Propel\Runtime\Connection\ConnectionManagerSingle(); $manager->setConfiguration(array ( 'classname' => '\\Propel\\Runtime\\Connection\\DebugPDO', 'dsn' => 'mysql:host=127.0.0.1;dbname=test', 'user' => 'root', 'password' => '', 'options' => array ( 'ATTR_PERSISTENT' => false, ), 'attributes' => array ( 'ATTR_EMULATE_PREPARES' => true, ), 'settings' => array ( 'charset' => 'utf8', ), )); $manager->setName('bookstore'); $serviceContainer->setConnectionManager('bookstore', $manager); $serviceContainer->setAdapterClass('bookstore-cms', 'mysql'); $manager = new \Propel\Runtime\Connection\ConnectionManagerMasterSlave(); $manager->setReadConfiguration(array ( 0 => array ( 'dsn' => 'mysql:host=slave-server1; dbname=bookstore', ), 1 => array ( 'dsn' => 'mysql:host=slave-server2; dbname=bookstore', ), )); $manager->setWriteConfiguration(array ( 'dsn' => 'mysql:host=localhost;dbname=bookstore', )); $manager->setName('bookstore-cms'); $serviceContainer->setConnectionManager('bookstore-cms', $manager); $serviceContainer->setDefaultDatasource('bookstore'); $serviceContainer->setLoggerConfiguration('defaultLogger', array ( 'type' => 'stream', 'level' => '300', 'path' => '/var/log/propel.log', )); EOF; $this->assertEquals($expected, ArrayToPhpConverter::convert($conf)); }