本文整理汇总了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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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();
}
示例6: getAll
public function getAll()
{
return Database::getAllConnectionInfo();
}
示例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');
}