class Schema

Same name in this branch
  1. 11.x core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema
  2. 11.x core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema
  3. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema
  4. 11.x core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php \Drupal\Tests\Core\Database\Stub\Driver\Schema
  5. 11.x core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Schema.php \Drupal\core_fake\Driver\Database\CoreFakeWithAllCustomClasses\Schema
  6. 11.x core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema
Same name and namespace in other branches
  1. 10 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema
  2. 10 core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema
  3. 10 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema
  4. 10 core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php \Drupal\Tests\Core\Database\Stub\Driver\Schema
  5. 10 core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Schema.php \Drupal\core_fake\Driver\Database\CoreFakeWithAllCustomClasses\Schema
  6. 10 core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php \Drupal\Core\Database\Driver\sqlite\Schema
  7. 10 core/lib/Drupal/Core/Database/Driver/mysql/Schema.php \Drupal\Core\Database\Driver\mysql\Schema
  8. 10 core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php \Drupal\Core\Database\Driver\pgsql\Schema
  9. 10 core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema
  10. 9 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema
  11. 9 core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema
  12. 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/Schema.php \Drupal\driver_test\Driver\Database\DrivertestMysql\Schema
  13. 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Schema.php \Drupal\driver_test\Driver\Database\DrivertestMysqlDeprecatedVersion\Schema
  14. 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Schema.php \Drupal\driver_test\Driver\Database\DrivertestPgsql\Schema
  15. 9 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema
  16. 9 core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php \Drupal\Tests\Core\Database\Stub\Driver\Schema
  17. 9 core/tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefakeWithAllCustomClasses/Schema.php \Drupal\corefake\Driver\Database\corefakeWithAllCustomClasses\Schema
  18. 9 core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php \Drupal\Core\Database\Driver\sqlite\Schema
  19. 9 core/lib/Drupal/Core/Database/Driver/mysql/Schema.php \Drupal\Core\Database\Driver\mysql\Schema
  20. 9 core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php \Drupal\Core\Database\Driver\pgsql\Schema
  21. 9 core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema
  22. 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/Schema.php \Drupal\driver_test\Driver\Database\DrivertestMysql\Schema
  23. 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Schema.php \Drupal\driver_test\Driver\Database\DrivertestPgsql\Schema
  24. 8.9.x core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php \Drupal\Tests\Core\Database\Stub\Driver\Schema
  25. 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php \Drupal\Core\Database\Driver\sqlite\Schema
  26. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Schema.php \Drupal\Core\Database\Driver\mysql\Schema
  27. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php \Drupal\Core\Database\Driver\pgsql\Schema
  28. 8.9.x core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema
  29. main core/modules/sqlite/src/Driver/Database/sqlite/Schema.php \Drupal\sqlite\Driver\Database\sqlite\Schema
  30. main core/modules/mysql/src/Driver/Database/mysql/Schema.php \Drupal\mysql\Driver\Database\mysql\Schema
  31. main core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema
  32. main core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php \Drupal\Tests\Core\Database\Stub\Driver\Schema
  33. main core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Schema.php \Drupal\core_fake\Driver\Database\CoreFakeWithAllCustomClasses\Schema
  34. main core/lib/Drupal/Core/Database/Schema.php \Drupal\Core\Database\Schema

Describes a database schema as a collection of database objects.

Hierarchy

Expanded class hierarchy of Schema

9 files declare their use of Schema
BatchStorage.php in core/lib/Drupal/Core/Batch/BatchStorage.php
database.api.php in core/lib/Drupal/Core/Database/database.api.php
Hooks related to the Database system and the Schema API.
KernelTestBase.php in core/tests/Drupal/KernelTests/KernelTestBase.php
locale.install in core/modules/locale/locale.install
Install, update, and uninstall functions for the Locale module.
ModuleInstaller.php in core/lib/Drupal/Core/Extension/ModuleInstaller.php

... See full list

3 string references to 'Schema'
ConnectionTest::providerGetDriverClass in core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
Data provider for testGetDriverClass().
HookCollectorPass::checkForProceduralOnlyHooks in core/lib/Drupal/Core/Hook/HookCollectorPass.php
Checks for hooks which can't be supported in classes.
HookCollectorPass::collectModuleHookImplementations in core/lib/Drupal/Core/Hook/HookCollectorPass.php
Collects procedural and Attribute hook implementations.

File

core/lib/Drupal/Core/Database/SchemaDefinition/Schema.php, line 13

Namespace

Drupal\Core\Database\SchemaDefinition
View source
final class Schema implements SchemaDefinitionInterface {
  
  /**
   * Constructor.
   *
   * @param SchemaDefinitionType $type
   *   The type of Drupal feature providing the schema.
   * @param string $name
   *   The schema name.
   * @param list<Table> $tables
   *   A list of Table objects.
   */
  public function __construct(public readonly SchemaDefinitionType $type, public readonly string $name, public readonly array $tables) {
    $this->validate();
  }
  
  /**
   * Validates the properties of the value object.
   *
   * @throws \Drupal\Core\Database\Exception\SchemaDefinitionException
   */
  private function validate() : void {
    if ($this->tables && !Inspector::assertAllObjects($this->tables, Table::class)) {
      throw new SchemaDefinitionException("All members of the 'tables' argument of a Schema must be Table objects");
    }
  }
  
  /**
   * Returns the names of the tables.
   *
   * @return list<string>
   *   The names of the tables.
   */
  public function tableNames() : array {
    return array_map(fn(Table $table): string => $table->name, $this->tables);
  }
  
  /**
   * Gets a specific table definition.
   *
   * @param string $name
   *   The name of the Table object to return.
   *
   * @return Table
   *   The Table object.
   *
   * @throws \Drupal\Core\Database\Exception\SchemaDefinitionException
   *   When the requested table is missing.
   */
  public function getTableDefinition(string $name) : Table {
    $ret = array_find($this->tables, function (Table $table) use ($name) : bool {
      return $table->name === $name;
    });
    if (!$ret) {
      throw new SchemaDefinitionException("Schema {$this->name} does not define a table named {$name}");
    }
    return $ret;
  }
  
  /**
   * {@inheritdoc}
   */
  public function toArray() : array {
    $spec = [];
    foreach ($this->tables as $table) {
      $spec[$table->name] = $table->toArray();
    }
    return $spec;
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.