public function register(Container $container)
 {
     $container->alias("db", "Joomla\\Database\\DatabaseDriver")->share("Joomla\\Database\\DatabaseDriver", function () use($container) {
         $config = $container->get("config");
         return DatabaseDriver::getInstance((array) $config["database"]);
     }, true);
 }
 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $container->alias('db', 'Joomla\\Database\\DatabaseDriver')->share('Joomla\\Database\\DatabaseDriver', function (Container $container) {
         $config = $container->get('config');
         return DatabaseDriver::getInstance((array) $config['database']);
     }, true);
 }
 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  void
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $container->alias('db', DatabaseDriver::class)->share(DatabaseDriver::class, function (Container $container) {
         $config = $container->get('config');
         $db = DatabaseDriver::getInstance((array) $config->get('database'));
         $db->setDebug($config->get('database.debug'));
         $db->setLogger($container->get('monolog.logger.database'));
         return $db;
     }, true);
 }
Exemplo n.º 4
0
 /**
  * This method is called before the first test of this test class is run.
  *
  * An example DSN would be: dbname=//localhost:1521/joomla_ut;charset=AL32UTF8;user=utuser;pass=ut1234
  *
  * @return  void
  *
  * @since   1.0
  */
 public static function setUpBeforeClass()
 {
     // First let's look to see if we have a DSN defined or in the environment variables.
     if (defined('JTEST_DATABASE_ORACLE_DSN') || getenv('JTEST_DATABASE_ORACLE_DSN')) {
         $dsn = defined('JTEST_DATABASE_ORACLE_DSN') ? JTEST_DATABASE_ORACLE_DSN : getenv('JTEST_DATABASE_ORACLE_DSN');
     } else {
         return;
     }
     // First let's trim the oci: part off the front of the DSN if it exists.
     if (strpos($dsn, 'oci:') === 0) {
         $dsn = substr($dsn, 4);
     }
     // Split the DSN into its parts over semicolons.
     $parts = explode(';', $dsn);
     // Parse each part and populate the options array.
     foreach ($parts as $part) {
         list($k, $v) = explode('=', $part, 2);
         switch ($k) {
             case 'charset':
                 self::$options['charset'] = $v;
                 break;
             case 'dbname':
                 $components = parse_url($v);
                 self::$options['host'] = $components['host'];
                 self::$options['port'] = $components['port'];
                 self::$options['database'] = ltrim($components['path'], '/');
                 break;
             case 'user':
                 self::$options['user'] = $v;
                 break;
             case 'pass':
                 self::$options['password'] = $v;
                 break;
             case 'dbschema':
                 self::$options['schema'] = $v;
                 break;
             case 'prefix':
                 self::$options['prefix'] = $v;
                 break;
         }
     }
     // Ensure some defaults.
     self::$options['charset'] = isset(self::$options['charset']) ? self::$options['charset'] : 'AL32UTF8';
     self::$options['port'] = isset(self::$options['port']) ? self::$options['port'] : 1521;
     try {
         // Attempt to instantiate the driver.
         self::$driver = DatabaseDriver::getInstance(self::$options);
     } catch (\RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof \Exception) {
         self::$driver = null;
     }
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $container)
 {
     $container->set('Joomla\\Database\\DatabaseDriver', function () use($container) {
         $config = $container->get('config');
         $options = array('driver' => $config->get('database.driver'), 'host' => $config->get('database.host'), 'user' => $config->get('database.user'), 'password' => $config->get('database.password'), 'database' => $config->get('database.name'), 'prefix' => $config->get('database.prefix'));
         $db = DatabaseDriver::getInstance($options);
         $db->setDebug($config->get('debug.database', false));
         return $db;
     }, true, true);
     // Alias the database
     $container->alias('db', 'Joomla\\Database\\DatabaseDriver');
 }
Exemplo n.º 6
0
 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container  $container  The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $container->set('Joomla\\Database\\DatabaseDriver', function () use($container) {
         $app = $container->get('app');
         $options = array('driver' => $app->get('database.driver'), 'host' => $app->get('database.host'), 'user' => $app->get('database.user'), 'password' => $app->get('database.password'), 'database' => $app->get('database.name'), 'prefix' => $app->get('database.prefix'));
         $db = DatabaseDriver::getInstance($options);
         $db->setDebug($app->get('debug.database', false));
         $logger = new Logger('JTracker-Database');
         $logger->pushHandler(new StreamHandler($app->get('debug.log-path', JPATH_ROOT) . '/database.log', Logger::ERROR));
         $logger->pushProcessor(new WebProcessor());
         $db->setLogger($logger);
         return $db;
     }, true, true);
     // Alias the database
     $container->alias('db', 'Joomla\\Database\\DatabaseDriver');
 }
Exemplo n.º 7
0
 /**
  * This method is called before the first test of this test class is run.
  *
  * An example DSN would be: host=localhost;port=5432;dbname=joomla_ut;user=utuser;pass=ut1234
  *
  * @return  void
  *
  * @since   1.0
  */
 public static function setUpBeforeClass()
 {
     // First let's look to see if we have a DSN defined or in the environment variables.
     if (defined('JTEST_DATABASE_PGSQL_DSN') || getenv('JTEST_DATABASE_PGSQL_DSN')) {
         $dsn = defined('JTEST_DATABASE_PGSQL_DSN') ? JTEST_DATABASE_PGSQL_DSN : getenv('JTEST_DATABASE_PGSQL_DSN');
     } else {
         return;
     }
     // First let's trim the pgsql: part off the front of the DSN if it exists.
     if (strpos($dsn, 'pgsql:') === 0) {
         $dsn = substr($dsn, 6);
     }
     // Split the DSN into its parts over semicolons.
     $parts = explode(';', $dsn);
     // Parse each part and populate the options array.
     foreach ($parts as $part) {
         list($k, $v) = explode('=', $part, 2);
         switch ($k) {
             case 'host':
                 self::$options['host'] = $v;
                 break;
             case 'port':
                 self::$options['port'] = $v;
                 break;
             case 'dbname':
                 self::$options['database'] = $v;
                 break;
             case 'user':
                 self::$options['user'] = $v;
                 break;
             case 'pass':
                 self::$options['password'] = $v;
                 break;
         }
     }
     try {
         // Attempt to instantiate the driver.
         self::$driver = DatabaseDriver::getInstance(self::$options);
     } catch (\RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof \Exception) {
         self::$driver = null;
     }
 }
Exemplo n.º 8
0
 /**
  * This method is called before the first test of this test class is run.
  *
  * @return  void
  *
  * @since   1.0
  */
 public static function setUpBeforeClass()
 {
     // We always want the default database test case to use an SQLite memory database.
     $options = array('driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'jos_');
     try {
         // Attempt to instantiate the driver.
         self::$driver = DatabaseDriver::getInstance($options);
         // Create a new PDO instance for an SQLite memory database and load the test schema into it.
         $pdo = new \PDO('sqlite::memory:');
         $pdo->exec(file_get_contents(__DIR__ . '/Schema/ddl.sql'));
         // Set the PDO instance to the driver using reflection whizbangery.
         TestHelper::setValue(self::$driver, 'connection', $pdo);
     } catch (\RuntimeException $e) {
         self::$driver = null;
     }
     // If for some reason an exception object was returned set our database object to null.
     if (self::$driver instanceof \Exception) {
         self::$driver = null;
     }
 }
Exemplo n.º 9
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->instance = \Joomla\Database\DatabaseDriver::getInstance(array('driver' => 'nosql', 'database' => 'europa', 'prefix' => '&'));
 }
Exemplo n.º 10
0
 /**
  * Return Database Object
  *
  * @param $driver
  * @param $host
  * @param $user
  * @param $password
  * @param $database
  * @param string $prefix
  * @param bool $select
  * @return DatabaseDriver
  */
 public function getDbo($driver, $host, $user, $password, $database, $prefix = '', $select = true)
 {
     static $db;
     if (!$db) {
         // Build the connection options array.
         $options = array('driver' => $driver, 'host' => $host, 'user' => $user, 'password' => $password, 'database' => $database, 'prefix' => $prefix, 'select' => $select);
         // Get a database object.
         $db = DatabaseDriver::getInstance($options);
     }
     return $db;
 }
Exemplo n.º 11
0
 /**
  * Get a database driver object.
  *
  * @return  DatabaseDriver
  *
  * @since   1.0
  */
 public function getDatabase()
 {
     if (is_null($this->database)) {
         $this->database = DatabaseDriver::getInstance(array('driver' => $this->get('database.driver'), 'host' => $this->get('database.host'), 'user' => $this->get('database.user'), 'password' => $this->get('database.password'), 'database' => $this->get('database.name'), 'prefix' => $this->get('database.prefix')));
         // @todo Decouple from Factory
         Factory::$database = $this->database;
     }
     return $this->database;
 }