You are here

public static function Runtime::getAhDatabaseRole in Acquia Search 3.x

Return the name of the Acquia "DB Role".

Acquia "DB Role" is in use when running inside an Acquia environment.

Parameters

array $options: Current connection options.

array $connection_info: ALl databases list.

Return value

string Database role.

2 calls to Runtime::getAhDatabaseRole()
Runtime::getPreferredSearchCoreService in src/Helper/Runtime.php
Instantiates the PreferredSearchCore class.
RuntimeTest::testGetAhDatabaseRole in tests/src/Unit/Helper/RuntimeTest.php
Tests getAhDatabaseRole.

File

src/Helper/Runtime.php, line 37

Class

Runtime
Class Runtime.

Namespace

Drupal\acquia_search\Helper

Code

public static function getAhDatabaseRole(array $options, array $connection_info) : string {
  $ah_db_name = $options['database'];

  // Scan all the available Databases and look for the currently-used DB name.
  foreach ($connection_info as $db_role => $db_array) {

    // Ignore the "default" connection, because even though it may match the
    // currently-used DB connection, this entry always exists and its key
    // won't match the AH "DB Role".
    if ($db_role == 'default') {
      continue;
    }
    if ($db_array['default']['database'] == $ah_db_name) {

      // In database role naming, we only accept alphanumeric chars.
      $pattern = '/[^a-zA-Z0-9_]+/';
      $db_role = preg_replace($pattern, '', $db_role);
      return $db_role;
    }
  }
  return '';
}