當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Database::getAllConnectionInfo方法代碼示例

本文整理匯總了PHP中Drupal\Core\Database\Database::getAllConnectionInfo方法的典型用法代碼示例。如果您正苦於以下問題:PHP Database::getAllConnectionInfo方法的具體用法?PHP Database::getAllConnectionInfo怎麽用?PHP Database::getAllConnectionInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Database\Database的用法示例。


在下文中一共展示了Database::getAllConnectionInfo方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: collect

 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = NULL)
 {
     $connections = [];
     foreach (Database::getAllConnectionInfo() as $key => $info) {
         $database = Database::getConnection('default', $key);
         $connections[$key] = $database->getLogger()->get('webprofiler');
     }
     $this->data['connections'] = array_keys($connections);
     $data = [];
     foreach ($connections as $key => $queries) {
         foreach ($queries as $query) {
             // Remove caller args.
             unset($query['caller']['args']);
             // Remove query args element if empty.
             if (empty($query['args'])) {
                 unset($query['args']);
             }
             // Save time in milliseconds.
             $query['time'] = $query['time'] * 1000;
             $query['database'] = $key;
             $data[] = $query;
         }
     }
     $querySort = $this->configFactory->get('webprofiler.config')->get('query_sort');
     if ('duration' === $querySort) {
         usort($data, ["Drupal\\webprofiler\\DataCollector\\DatabaseDataCollector", "orderQueryByTime"]);
     }
     $this->data['queries'] = $data;
     $options = $this->database->getConnectionOptions();
     // Remove password for security.
     unset($options['password']);
     $this->data['database'] = $options;
 }
開發者ID:sgtsaughter,項目名稱:d8portfolio,代碼行數:36,代碼來源:DatabaseDataCollector.php

示例2: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     foreach (Database::getAllConnectionInfo() as $key => $info) {
         Database::startLog('webprofiler', $key);
     }
     return $this->httpKernel->handle($request, $type, $catch);
 }
開發者ID:penguinclub,項目名稱:penguinweb_drupal8,代碼行數:10,代碼來源:WebprofilerMiddleware.php

示例3: tearDownCloseDatabaseConnection

 /**
  * @after
  *
  * Additional tear down method to close the connection at the end.
  */
 public function tearDownCloseDatabaseConnection()
 {
     // Destroy the database connection, which for example removes the memory
     // from sqlite in memory.
     foreach (Database::getAllConnectionInfo() as $key => $targets) {
         Database::removeConnection($key);
     }
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:13,代碼來源:KernelTestBase.php

示例4: buildConfigurationForm

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    // Discern between creation and editing of a server, since we don't allow
    // the database to be changed later on.
    if (!$this->configuration['database']) {
      $options = array();
      $key = $target = '';
      foreach (CoreDatabase::getAllConnectionInfo() as $key => $targets) {
        foreach ($targets as $target => $info) {
          $options[$key]["$key:$target"] = "$key » $target";
        }
      }
      if (count($options) > 1 || count(reset($options)) > 1) {
        $form['database'] = array(
          '#type' => 'select',
          '#title' => $this->t('Database'),
          '#description' => $this->t('Select the database key and target to use for storing indexing information in. ' .
              'Cannot be changed after creation.'),
          '#options' => $options,
          '#default_value' => 'default:default',
          '#required' => TRUE,
        );
      }
      else {
        $form['database'] = array(
          '#type' => 'value',
          '#value' => "$key:$target",
        );
      }
    }
    else {
      $form = array(
        'database' => array(
          '#type' => 'value',
          '#title' => $this->t('Database'),
          '#value' => $this->configuration['database'],
        ),
        'database_text' => array(
          '#type' => 'item',
          '#title' => $this->t('Database'),
          '#plain_text' => str_replace(':', ' > ', $this->configuration['database']),
        ),
      );
    }

    $form['min_chars'] = array(
      '#type' => 'select',
      '#title' => $this->t('Minimum word length'),
      '#description' => $this->t('The minimum number of characters a word must consist of to be indexed'),
      '#options' => array_combine(array(1, 2, 3, 4, 5, 6), array(1, 2, 3, 4, 5, 6)),
      '#default_value' => $this->configuration['min_chars'],
    );

    if ($this->getModuleHandler()->moduleExists('search_api_autocomplete')) {
      $form['autocomplete'] = array(
        '#type' => 'details',
        '#title' => $this->t('Autocomplete settings'),
        '#description' => $this->t('These settings allow you to configure how suggestions are computed when autocompletion is used. If you are seeing many inappropriate suggestions you might want to deactivate the corresponding suggestion type. You can also deactivate one method to speed up the generation of suggestions.'),
      );
      $form['autocomplete']['suggest_suffix'] = array(
        '#type' => 'checkbox',
        '#title' => $this->t('Suggest word endings'),
        '#description' => $this->t('Suggest endings for the currently entered word.'),
        '#default_value' => $this->configuration['autocomplete']['suggest_suffix'],
      );
      $form['autocomplete']['suggest_words'] = array(
        '#type' => 'checkbox',
        '#title' => $this->t('Suggest additional words'),
        '#description' => $this->t('Suggest additional words the user might want to search for.'),
        '#default_value' => $this->configuration['autocomplete']['suggest_words'],
      );
    }

    return $form;
  }
開發者ID:jkyto,項目名稱:agolf,代碼行數:77,代碼來源:Database.php

示例5: tearDown

 /**
  * {@inheritdoc}
  */
 protected function tearDown()
 {
     // Destroy the testing kernel.
     if (isset($this->kernel)) {
         $this->kernel->shutdown();
     }
     // Free up memory: Own properties.
     $this->classLoader = NULL;
     $this->vfsRoot = NULL;
     $this->configImporter = NULL;
     // Free up memory: Custom test class properties.
     // Note: Private properties cannot be cleaned up.
     $rc = new \ReflectionClass(__CLASS__);
     $blacklist = array();
     foreach ($rc->getProperties() as $property) {
         $blacklist[$property->name] = $property->getDeclaringClass()->name;
     }
     $rc = new \ReflectionClass($this);
     foreach ($rc->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $property) {
         if (!$property->isStatic() && !isset($blacklist[$property->name])) {
             $this->{$property->name} = NULL;
         }
     }
     // Clean up statics, container, and settings.
     if (function_exists('drupal_static_reset')) {
         drupal_static_reset();
     }
     \Drupal::unsetContainer();
     $this->container = NULL;
     new Settings(array());
     // Destroy the database connection, which for example removes the memory
     // from sqlite in memory.
     foreach (Database::getAllConnectionInfo() as $key => $targets) {
         Database::removeConnection($key);
     }
     parent::tearDown();
 }
開發者ID:scratch,項目名稱:gai,代碼行數:40,代碼來源:KernelTestBase.php

示例6: getAll

 public function getAll()
 {
     return Database::getAllConnectionInfo();
 }
開發者ID:bjargud,項目名稱:drush,代碼行數:4,代碼來源:Sql8.php

示例7: 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::getAllConnectionInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。