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


PHP Database::setMultipleConnectionInfo方法代码示例

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


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

示例1: __construct

 public function __construct($database)
 {
     global $ss_client;
     $this->root = dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
     require_once DRUPAL_ROOT . '/core/includes/database.inc';
     Database::setMultipleConnectionInfo($database);
     $this->connection = Database::getConnection();
     $this->ss_client =& $ss_client;
     $this->database = $database;
     $query = db_select('config', 'n')->fields('n')->condition('name', $this->options, 'IN');
     $result = $query->execute();
     if ($result && is_object($result)) {
         foreach ($result as $key => $row) {
             $values = unserialize($row->data);
             foreach ($values[key($values)] as $value_key => $value) {
                 $this->data_options[$value_key] = $value;
             }
         }
     }
     if (defined('STACKSIGHT_SETTINGS_IN_DB') && STACKSIGHT_SETTINGS_IN_DB === true) {
         if (isset($this->data_options['token'])) {
             $this->ready = true;
         }
     } else {
         $this->ready = true;
     }
     define('STACKSIGHT_PHP_SDK_INCLUDE', TRUE);
 }
开发者ID:stacksight,项目名称:stacksight-php-sdk,代码行数:28,代码来源:bootstrap-drupal-8.php

示例2: initialize

 /**
  * Bootstraps settings.php and the Settings singleton.
  *
  * @param string $app_root
  *   The app root.
  * @param string $site_path
  *   The current site path.
  * @param \Composer\Autoload\ClassLoader $class_loader
  *   The class loader that is used for this request. Passed by reference and
  *   exposed to the local scope of settings.php, so as to allow it to be
  *   decorated with Symfony's ApcClassLoader, for example.
  *
  * @see default.settings.php
  */
 public static function initialize($app_root, $site_path, &$class_loader)
 {
     // Export these settings.php variables to the global namespace.
     global $config_directories, $config;
     $settings = array();
     $config = array();
     $databases = array();
     if (is_readable($app_root . '/' . $site_path . '/settings.php')) {
         require $app_root . '/' . $site_path . '/settings.php';
     }
     // Initialize Database.
     Database::setMultipleConnectionInfo($databases);
     // Initialize Settings.
     new Settings($settings);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:29,代码来源:Settings.php

示例3: initialize

 /**
  * Bootstraps settings.php and the Settings singleton.
  *
  * @param string $site_path
  *   The current site path.
  */
 public static function initialize($site_path)
 {
     // Export these settings.php variables to the global namespace.
     global $base_url, $cookie_domain, $config_directories, $config;
     $settings = array();
     $config = array();
     $databases = array();
     // Make conf_path() available as local variable in settings.php.
     if (is_readable(DRUPAL_ROOT . '/' . $site_path . '/settings.php')) {
         require DRUPAL_ROOT . '/' . $site_path . '/settings.php';
     }
     // Initialize Database.
     Database::setMultipleConnectionInfo($databases);
     // Initialize Settings.
     new Settings($settings);
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:22,代码来源:Settings.php

示例4: testConnectionSerialization

 /**
  * Tests the serialization and unserialization of a database connection.
  */
 public function testConnectionSerialization()
 {
     $db = Database::getConnection('default', 'default');
     try {
         $serialized = serialize($db);
         $this->pass('The database connection can be serialized.');
         $unserialized = unserialize($serialized);
         $this->assertTrue(get_class($unserialized) === get_class($db));
     } catch (\Exception $e) {
         $this->fail('The database connection cannot be serialized.');
     }
     // Ensure that all properties on the unserialized object are the same.
     $db_reflection = new \ReflectionObject($db);
     $unserialized_reflection = new \ReflectionObject($unserialized);
     foreach ($db_reflection->getProperties() as $value) {
         $value->setAccessible(TRUE);
         // Skip properties that are lazily populated on access.
         if ($value->getName() === 'driverClasses' || $value->getName() === 'schema') {
             continue;
         }
         $unserialized_property = $unserialized_reflection->getProperty($value->getName());
         $unserialized_property->setAccessible(TRUE);
         // For the PDO object, just check the statement class attribute.
         if ($value->getName() == 'connection') {
             $db_statement_class = $unserialized_property->getValue($db)->getAttribute(\PDO::ATTR_STATEMENT_CLASS);
             $unserialized_statement_class = $unserialized_property->getValue($unserialized)->getAttribute(\PDO::ATTR_STATEMENT_CLASS);
             // Assert the statement class.
             $this->assertEqual($unserialized_statement_class[0], $db_statement_class[0]);
             // Assert the connection argument that is passed into the statement.
             $this->assertEqual(get_class($unserialized_statement_class[1][0]), get_class($db_statement_class[1][0]));
         } else {
             $actual = $unserialized_property->getValue($unserialized);
             $expected = $value->getValue($db);
             $this->assertEqual($actual, $expected, vsprintf('Unserialized Connection property %s value %s is equal to expected %s', array(var_export($value->getName(), TRUE), is_object($actual) ? print_r($actual, TRUE) : var_export($actual, TRUE), is_object($expected) ? print_r($expected, TRUE) : var_export($expected, TRUE))));
         }
     }
     // By using "key", we ensure that its not a key used in the serialized PHP.
     $not_serialized_properties = ['"connection"', '"connectionOptions"', '"schema"', '"prefixes"', '"prefixReplace"', '"driverClasses"'];
     foreach ($not_serialized_properties as $property) {
         $this->assertIdentical(FALSE, strpos($serialized, $property));
     }
     // Serialize the DB connection again, but this time change the connection
     // information under the hood.
     $serialized = serialize($db);
     $db_connection_info = Database::getAllConnectionInfo();
     // Use reflection to empty out $databaseInfo.
     $reflection_class = new \ReflectionClass('Drupal\\Core\\Database\\Database');
     $database_info_reflection = $reflection_class->getProperty('databaseInfo');
     $database_info_reflection->setAccessible(TRUE);
     $database_info_reflection->setValue(NULL, []);
     // Setup a different DB connection which should be picked up after the
     // unserialize.
     $db_connection_info['default']['default']['extra'] = 'value';
     Database::setMultipleConnectionInfo($db_connection_info);
     /** @var \Drupal\Core\Database\Connection $db */
     $db = unserialize($serialized);
     $this->assertEqual($db->getConnectionOptions()['extra'], 'value');
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:61,代码来源:ConnectionUnitTest.php


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