From 5c119fa53ee61599d59239932682bcbe7b9284fa Mon Sep 17 00:00:00 2001 From: Markus Fasselt Date: Fri, 24 Aug 2018 15:08:48 +0200 Subject: [PATCH] Allow to specify pdo options --- demo.yml | 5 ++++- src/Command/DumpCommand.php | 2 +- src/Configuration/DatabaseConfiguration.php | 18 ++++++++++++++++++ src/Configuration/SnakeConfigurationTree.php | 4 ++++ src/Dumper/Sql/ConnectionHandler.php | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/demo.yml b/demo.yml index 0d2f11c..c19a87b 100644 --- a/demo.yml +++ b/demo.yml @@ -5,11 +5,14 @@ output: gzip: false database: driver: pdo_mysql - host: localhost + host: 127.0.0.1 user: root password: '' dbname: demo charset: UTF8 + pdo_options: + !php/const PDO::MYSQL_ATTR_SSL_CA: './path-to-ca.pem' + !php/const PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT: true table_white_list: - foo diff --git a/src/Command/DumpCommand.php b/src/Command/DumpCommand.php index 827fd23..ee721da 100644 --- a/src/Command/DumpCommand.php +++ b/src/Command/DumpCommand.php @@ -74,7 +74,7 @@ private function parseConfig(InputInterface $input) throw new \InvalidArgumentException('Cannot find configuration file: ' . $configArg); } - $config = Yaml::parse(file_get_contents($configFile)); + $config = Yaml::parse(file_get_contents($configFile), Yaml::PARSE_CONSTANT); $processor = new Processor(); $configuration = new SnakeConfigurationTree(); diff --git a/src/Configuration/DatabaseConfiguration.php b/src/Configuration/DatabaseConfiguration.php index 7997c75..478ba67 100644 --- a/src/Configuration/DatabaseConfiguration.php +++ b/src/Configuration/DatabaseConfiguration.php @@ -134,6 +134,24 @@ public function getConnection() return $this->get('connection'); } + /** + * @return array + */ + public function getPdoOptions() + { + return $this->get('pdo_options'); + } + + /** + * @param array $options + * + * @return DatabaseConfiguration + */ + public function setPdoOptions(array $options) + { + return $this->set('pdo_options', $options); + } + protected function parseConfig(array $config) { if (!isset($config['connection'])) { diff --git a/src/Configuration/SnakeConfigurationTree.php b/src/Configuration/SnakeConfigurationTree.php index 2138e9c..603aab3 100644 --- a/src/Configuration/SnakeConfigurationTree.php +++ b/src/Configuration/SnakeConfigurationTree.php @@ -43,6 +43,10 @@ public function getConfigTreeBuilder() ->scalarNode('password')->end() ->scalarNode('dbname')->end() ->scalarNode('charset')->end() + ->arrayNode('pdo_options') + ->prototype('scalar') + ->end() + ->end() ->end() ->end() ; diff --git a/src/Dumper/Sql/ConnectionHandler.php b/src/Dumper/Sql/ConnectionHandler.php index 946dcd9..e2e6d31 100644 --- a/src/Dumper/Sql/ConnectionHandler.php +++ b/src/Dumper/Sql/ConnectionHandler.php @@ -119,6 +119,7 @@ private function connect() 'dbname' => $this->config->getDatabaseName(), 'charset' => $this->config->getCharset(), 'wrapperClass' => \Digilist\SnakeDumper\Dumper\Bridge\Doctrine\DBAL\Connection::class, + 'driverOptions' => $this->config->getPdoOptions(), ); $dbalConfig = new Configuration();