You are here

public function System::get in Schema 8

Parameters

bool $rebuild: Whether to force a rebuild of schema data.

Return value

array Array of schema information, keyed by table.

Overrides SchemaProviderInterface::get

File

src/Plugin/Schema/System.php, line 31
Contains Drupal\schema\Plugin\Schema\System.

Class

System
Provides schema information defined by modules in implementations of hook_schema().

Namespace

Drupal\schema\Plugin\Schema

Code

public function get($rebuild = FALSE) {

  //
  static $schema;
  if (!isset($schema) || $rebuild) {

    // Try to load the schema from cache.
    if (!$rebuild && ($cached = \Drupal::cache()
      ->get(self::CACHE_BIN))) {
      $schema = $cached->data;
    }
    else {
      $schema = array();

      // Load the .install files to get hook_schema.
      \Drupal::moduleHandler()
        ->loadAllIncludes('install');
      require_once DRUPAL_ROOT . '/core/includes/common.inc';

      // Invoke hook_schema for all modules.
      foreach (\Drupal::moduleHandler()
        ->getImplementations('schema') as $module) {

        // Cast the result of hook_schema() to an array, as a NULL return value
        // would cause array_merge() to set the $schema variable to NULL as well.
        // That would break modules which use $schema further down the line.
        $current = (array) \Drupal::moduleHandler()
          ->invoke($module, 'schema');

        // Set 'module' and 'name' keys for each table.
        _drupal_schema_initialize($current, $module, FALSE);
        $schema = array_merge($schema, $current);
      }
      \Drupal::moduleHandler()
        ->alter('schema', $schema);

      // If the schema is empty, avoid saving it: some database engines require
      // the schema to perform queries, and this could lead to infinite loops.
      if (!empty($schema)) {
        \Drupal::cache()
          ->set(self::CACHE_BIN, $schema, Cache::PERMANENT);
      }
    }
  }
  return $schema;
}