Author: Tim Wagner (tw@appserver.io)
Inheritance: extends AppserverIo\Configuration\Interfaces\NodeInterface
 /**
  * Convert's the passed database node into a DTO.
  *
  * @param \AppserverIo\Appserver\Core\Api\Node\DatabaseNodeInterface $databaseNode The datgabase node to convert
  *
  * @return \AppserverIo\Apps\Api\TransferObject\DatabaseOverviewData The DTO
  */
 public function toDatabaseOverviewData(DatabaseNodeInterface $databaseNode)
 {
     $overviewData = new DatabaseOverviewData();
     $overviewData->setId($databaseNode->getPrimaryKey());
     $overviewData->setCharset((string) $databaseNode->getCharset());
     $overviewData->setDatabaseHost((string) $databaseNode->getDatabaseHost());
     $overviewData->setDatabaseName((string) $databaseNode->getDatabaseName());
     $overviewData->setDatabasePort((int) $databaseNode->getDatabasePort());
     $overviewData->setDriver((string) $databaseNode->getDriver());
     $overviewData->setDriverOptions((string) $databaseNode->getDriverOptions());
     $overviewData->setMemory((bool) $databaseNode->getMemory());
     $overviewData->setPassword((string) $databaseNode->getPassword());
     $overviewData->setPath((string) $databaseNode->getPath());
     $overviewData->setUnixSocket((string) $databaseNode->getUnixSocket());
     $overviewData->setUser((string) $databaseNode->getUser());
     return $overviewData;
 }
Esempio n. 2
0
 /**
  * Creates an array with the connection parameters for a Doctrine DBAL connection from
  * the passed database node.
  *
  * @param AppserverIo\Appserver\Core\Api\Node\DatabaseNodeInterface $databaseNode The database node to create the connection parameters from
  *
  * @return array The DBAL connection parameters
  */
 public function fromDatabaseNode(DatabaseNodeInterface $databaseNode)
 {
     // initialize the connection parameters with the mandatory driver
     $connectionParameters = array('driver' => $databaseNode->getDriver()->getNodeValue()->__toString());
     // initialize the path/memory to the database when we use sqlite for example
     if ($pathNode = $databaseNode->getPath()) {
         $connectionParameters['path'] = $this->getApplication()->getWebappPath() . DIRECTORY_SEPARATOR . $pathNode->getNodeValue()->__toString();
     } elseif ($memoryNode = $databaseNode->getMemory()) {
         $connectionParameters['memory'] = Boolean::valueOf(new String($memoryNode->getNodeValue()->__toString()))->booleanValue();
     } else {
         // do nothing here, because there is NO option
     }
     // add username, if specified
     if ($userNode = $databaseNode->getUser()) {
         $connectionParameters['user'] = $userNode->getNodeValue()->__toString();
     }
     // add password, if specified
     if ($passwordNode = $databaseNode->getPassword()) {
         $connectionParameters['password'] = $passwordNode->getNodeValue()->__toString();
     }
     // add database name if using another PDO driver than sqlite
     if ($databaseNameNode = $databaseNode->getDatabaseName()) {
         $connectionParameters['dbname'] = $databaseNameNode->getNodeValue()->__toString();
     }
     // add database host if using another PDO driver than sqlite
     if ($databaseHostNode = $databaseNode->getDatabaseHost()) {
         $connectionParameters['host'] = $databaseHostNode->getNodeValue()->__toString();
     }
     // add database port if using another PDO driver than sqlite
     if ($databasePortNode = $databaseNode->getDatabasePort()) {
         $connectionParameters['port'] = $databasePortNode->getNodeValue()->__toString();
     }
     // add charset, if specified
     if ($charsetNode = $databaseNode->getCharset()) {
         $connectionParameters['charset'] = $charsetNode->getNodeValue()->__toString();
     }
     // add driver options, if specified
     if ($unixSocketNode = $databaseNode->getUnixSocket()) {
         $connectionParameters['unix_socket'] = $unixSocketNode->getNodeValue()->__toString();
     }
     // add server version, if specified
     if ($serverVersionNode = $databaseNode->getServerVersion()) {
         $connectionParameters['server_version'] = $serverVersionNode->getNodeValue()->__toString();
     }
     // set platform, if specified
     if ($platformNode = $databaseNode->getPlatform()) {
         $platform = $platformNode->getNodeValue()->__toString();
         $connectionParameters['platform'] = new $platform();
     }
     // add driver options, if specified
     if ($driverOptionsNode = $databaseNode->getDriverOptions()) {
         // explode the raw options separated with a semicolon
         $rawOptions = explode(';', $driverOptionsNode->getNodeValue()->__toString());
         // prepare the array with the driver options key/value pair (separated with a =)
         $options = array();
         foreach ($rawOptions as $rawOption) {
             list($key, $value) = explode('=', $rawOption);
             $options[$key] = $value;
         }
         // set the driver options
         $connectionParameters['driverOptions'] = $options;
     }
     // returns the connection parameters
     return $connectionParameters;
 }