parse() public method

public parse ( $dsn )
 public function execute()
 {
     $configLoader = $this->getConfigLoader(true);
     $dsId = $this->getCurrentDataSourceId();
     $ds = $configLoader->getDataSource($dsId);
     $dsnParser = new DSNParser();
     $dsn = $dsnParser->parse($ds['dsn']);
     $dbName = $dsn->getAttribute('dbname');
     $dsn->removeAttribute('dbname');
     $this->logger->debug("Connection DSN: " . $dsn);
     $pdo = new PDO($dsn, @$ds['user'], @$ds['pass'], @$ds['connection_options']);
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $q = new DropDatabaseQuery($dbName);
     $q->ifExists();
     // Create query Driver object
     $queryDriver = PDODriverFactory::create($pdo);
     $sql = $q->toSql($queryDriver, new ArgumentArray());
     $this->logger->info($sql);
     if ($pdo->query($sql) === false) {
         list($statusCode, $errorCode, $message) = $pdo->errorInfo();
         $this->logger->error("{$statusCode}:{$errorCode} {$message}");
         return false;
     }
     $this->logger->info('Database dropped successfully.');
 }
Exemplo n.º 2
0
 public function execute($dataSourceId, $dsnStr)
 {
     // force loading data source
     $configLoader = $this->getConfigLoader(true);
     // The data source array to be added to the config array
     $dataSource = array();
     $dsnParser = new DSNParser();
     $dsn = $dsnParser->parse($dsnStr);
     if ($host = $this->options->host) {
         $dsn->setAttribute('host', $host);
     }
     if ($port = $this->options->port) {
         $dsn->setAttribute('port', $port);
     }
     $dataSource['dsn'] = $dsn->__toString();
     if ($user = $this->options->user) {
         $dataSource['user'] = $user;
     }
     if ($password = $this->options->password) {
         $dataSource['pass'] = $password;
     }
     $config = $configLoader->getConfigStash();
     $config['data_source']['nodes'][$dataSourceId] = $dataSource;
     $configLoader->setConfigStash($config);
     $configLoader->writeToSymbol();
     return true;
 }
Exemplo n.º 3
0
 public function getDSN()
 {
     if ($this->dsn) {
         return $this->dsn;
     }
     $parser = new DSNParser();
     return $this->dsn = $parser->parse($this->config['dsn']);
 }
Exemplo n.º 4
0
 public function execute($dataSourceId, $dsnStr)
 {
     // force loading data source
     $configLoader = $this->getConfigLoader(true);
     // The data source array to be added to the config array
     $dataSource = array();
     $dsnParser = new DSNParser();
     $dsn = $dsnParser->parse($dsnStr);
     $dataSource['driver'] = $dsn->getDriver();
     if ($host = $this->options->host) {
         $dsn->setAttribute('host', $host);
         $dataSource['host'] = $host;
     }
     if ($port = $this->options->port) {
         $dsn->setAttribute('port', $port);
         $dataSource['port'] = $port;
     }
     // mysql only attribute
     if ($dbname = $dsn->getAttribute('dbname')) {
         $dataSource['database'] = $dbname;
     }
     if ($user = $this->options->user) {
         $dataSource['user'] = $user;
     }
     if ($password = $this->options->password) {
         $dataSource['pass'] = $password;
     }
     $dataSource['dsn'] = $dsn->__toString();
     if ($dsn->getDriver() == 'mysql') {
         $this->logger->debug('Setting connection options: PDO::MYSQL_ATTR_INIT_COMMAND');
         $dataSource['connection_options'] = [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'];
     }
     $config = $configLoader->getConfigStash();
     $config['data_source']['nodes'][$dataSourceId] = $dataSource;
     $configLoader->setConfigStash($config);
     $configLoader->writeToSymbol();
     return true;
 }
Exemplo n.º 5
0
 public function execute()
 {
     $configLoader = $this->getConfigLoader(true);
     $dsId = $this->getCurrentDataSourceId();
     $ds = $configLoader->getDataSource($dsId);
     if (!isset($ds['dsn'])) {
         throw new Exception("Attribute 'dsn' undefined in data source settings.");
     }
     $dsnParser = new DSNParser();
     $dsn = $dsnParser->parse($ds['dsn']);
     $dbName = $dsn->getAttribute('dbname');
     $dsn->removeAttribute('dbname');
     $this->logger->debug("Connection DSN: " . $dsn);
     $pdo = new PDO($dsn, @$ds['user'], @$ds['pass'], @$ds['connection_options']);
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     $queryDriver = PDODriverFactory::create($pdo);
     if ($queryDriver instanceof PDOSQLiteDriver) {
         $this->logger->info('Create database query is not supported by sqlite. ths sqlite database shall have been created.');
         return true;
     }
     $q = new CreateDatabaseQuery($dbName);
     $q->ifNotExists();
     if (isset($ds['charset'])) {
         $q->characterSet($ds['charset']);
     } else {
         $q->characterSet('utf8');
     }
     $sql = $q->toSql($queryDriver, new ArgumentArray());
     $this->logger->info($sql);
     if ($pdo->query($sql) === false) {
         list($statusCode, $errorCode, $message) = $pdo->errorInfo();
         $this->logger->error("{$statusCode}:{$errorCode} {$message}");
         return false;
     }
     $this->logger->info('Database created successfully.');
 }
 /**
  * @dataProvider dsnProvider
  */
 public function testParse($dsn)
 {
     $parser = new DSNParser();
     $dsnObject = $parser->parse($dsn);
     $this->assertNotNull($dsnObject);
 }