Schema.php
Same filename in this branch
- 11.x core/modules/sqlite/src/Driver/Database/sqlite/Schema.php
- 11.x core/modules/mysql/src/Driver/Database/mysql/Schema.php
- 11.x core/modules/pgsql/src/Driver/Database/pgsql/Schema.php
- 11.x core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php
- 11.x core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Schema.php
- 11.x core/lib/Drupal/Core/Database/Schema.php
Same filename and directory in other branches
- 10 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php
- 10 core/modules/mysql/src/Driver/Database/mysql/Schema.php
- 10 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php
- 10 core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php
- 10 core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Schema.php
- 10 core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
- 10 core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
- 10 core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
- 10 core/lib/Drupal/Core/Database/Schema.php
- 9 core/modules/sqlite/src/Driver/Database/sqlite/Schema.php
- 9 core/modules/mysql/src/Driver/Database/mysql/Schema.php
- 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/Schema.php
- 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysqlDeprecatedVersion/Schema.php
- 9 core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Schema.php
- 9 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php
- 9 core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php
- 9 core/tests/fixtures/database_drivers/module/corefake/src/Driver/Database/corefakeWithAllCustomClasses/Schema.php
- 9 core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
- 9 core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
- 9 core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
- 9 core/lib/Drupal/Core/Database/Schema.php
- 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql/Schema.php
- 8.9.x core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/Schema.php
- 8.9.x core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php
- 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
- 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
- 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
- 8.9.x core/lib/Drupal/Core/Database/Schema.php
- main core/modules/sqlite/src/Driver/Database/sqlite/Schema.php
- main core/modules/mysql/src/Driver/Database/mysql/Schema.php
- main core/modules/pgsql/src/Driver/Database/pgsql/Schema.php
- main core/tests/Drupal/Tests/Core/Database/Stub/Driver/Schema.php
- main core/tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses/Schema.php
- main core/lib/Drupal/Core/Database/Schema.php
Namespace
Drupal\Core\Database\SchemaDefinitionFile
-
core/
lib/ Drupal/ Core/ Database/ SchemaDefinition/ Schema.php
View source
<?php
declare (strict_types=1);
namespace Drupal\Core\Database\SchemaDefinition;
use Drupal\Component\Assertion\Inspector;
use Drupal\Core\Database\Exception\SchemaDefinitionException;
/**
* Describes a database schema as a collection of database objects.
*/
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;
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| Schema | Describes a database schema as a collection of database objects. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.