当前位置: 首页>>代码示例>>PHP>>正文


PHP Database::convertDbUrlToConnectionInfo方法代码示例

本文整理汇总了PHP中Drupal\Core\Database\Database::convertDbUrlToConnectionInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::convertDbUrlToConnectionInfo方法的具体用法?PHP Database::convertDbUrlToConnectionInfo怎么用?PHP Database::convertDbUrlToConnectionInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Database\Database的用法示例。


在下文中一共展示了Database::convertDbUrlToConnectionInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDatabaseConnection

 /**
  * Parse input options decide on a database.
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  *   Input object.
  * @return \Drupal\Core\Database\Connection
  */
 protected function getDatabaseConnection(InputInterface $input)
 {
     // Load connection from a url.
     if ($input->getOption('database-url')) {
         // @todo this could probably be refactored to not use a global connection.
         // Ensure database connection isn't set.
         if (Database::getConnectionInfo('db-tools')) {
             throw new \RuntimeException('Database "db-tools" is already defined. Cannot define database provided.');
         }
         $info = Database::convertDbUrlToConnectionInfo($input->getOption('database-url'), \Drupal::root());
         Database::addConnectionInfo('db-tools', 'default', $info);
         $key = 'db-tools';
     } else {
         $key = $input->getOption('database');
     }
     // If they supplied a prefix, replace it in the connection information.
     $prefix = $input->getOption('prefix');
     if ($prefix) {
         $info = Database::getConnectionInfo($key)['default'];
         $info['prefix']['default'] = $prefix;
         Database::removeConnection($key);
         Database::addConnectionInfo($key, 'default', $info);
     }
     return Database::getConnection('default', $key);
 }
开发者ID:318io,项目名称:318-io,代码行数:32,代码来源:DbCommandBase.php

示例2: changeDatabasePrefix

 /**
  * Changes the database connection to the prefixed one.
  *
  * @see BrowserTestBase::prepareEnvironment()
  */
 private function changeDatabasePrefix()
 {
     if (empty($this->databasePrefix)) {
         $this->prepareDatabasePrefix();
     }
     // If the test is run with argument dburl then use it.
     $db_url = getenv('SIMPLETEST_DB');
     if (!empty($db_url)) {
         $database = Database::convertDbUrlToConnectionInfo($db_url, DRUPAL_ROOT);
         Database::addConnectionInfo('default', 'default', $database);
     }
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     if (is_null($connection_info)) {
         throw new \InvalidArgumentException('There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh.');
     } else {
         Database::renameConnection('default', 'simpletest_original_default');
         foreach ($connection_info as $target => $value) {
             // Replace the full table prefix definition to ensure that no table
             // prefixes of the test runner leak into the test.
             $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
         }
         Database::addConnectionInfo('default', 'default', $connection_info['default']);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:30,代码来源:BrowserTestBase.php

示例3: getDatabaseConnectionInfo

 /**
  * Returns the Database connection info to be used for this test.
  *
  * This method only exists for tests of the Database component itself, because
  * they require multiple database connections. Each SQLite :memory: connection
  * creates a new/separate database in memory. A shared-memory SQLite file URI
  * triggers PHP open_basedir/allow_url_fopen/allow_url_include restrictions.
  * Due to that, Database tests are running against a SQLite database that is
  * located in an actual file in the system's temporary directory.
  *
  * Other tests should not override this method.
  *
  * @return array
  *   A Database connection info array.
  *
  * @internal
  */
 protected function getDatabaseConnectionInfo()
 {
     // If the test is run with argument dburl then use it.
     $db_url = getenv('SIMPLETEST_DB');
     if (empty($db_url)) {
         throw new \Exception('There is no database connection so no tests can be run. You must provide a SIMPLETEST_DB environment variable to run PHPUnit based functional tests outside of run-tests.sh. See https://www.drupal.org/node/2116263#skipped-tests for more information.');
     } else {
         $database = Database::convertDbUrlToConnectionInfo($db_url, $this->root);
         Database::addConnectionInfo('default', 'default', $database);
     }
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
     if (!empty($connection_info)) {
         Database::renameConnection('default', 'simpletest_original_default');
         foreach ($connection_info as $target => $value) {
             // Replace the full table prefix definition to ensure that no table
             // prefixes of the test runner leak into the test.
             $connection_info[$target]['prefix'] = array('default' => $value['prefix']['default'] . $this->databasePrefix);
         }
     }
     return $connection_info;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:39,代码来源:KernelTestBase.php

示例4: testGetInvalidArgumentExceptionInUrlConversion

 /**
  * Test ::convertDbUrlToConnectionInfo() exception for invalid arguments.
  *
  * @dataProvider providerInvalidArgumentsUrlConversion
  */
 public function testGetInvalidArgumentExceptionInUrlConversion($url, $root)
 {
     $this->setExpectedException(\InvalidArgumentException::class);
     Database::convertDbUrlToConnectionInfo($url, $root);
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:10,代码来源:UrlConversionTest.php


注:本文中的Drupal\Core\Database\Database::convertDbUrlToConnectionInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。