Documentation

Schema extends AbstractAsset
in package

Object representation of a database schema.

Different vendors have very inconsistent naming with regard to the concept of a "schema". Doctrine understands a schema as the entity that conceptually wraps a set of database objects such as tables, sequences, indexes and foreign keys that belong to each other into a namespace. A Doctrine Schema has nothing to do with the "SCHEMA" defined as in PostgreSQL, it is more related to the concept of "DATABASE" that exists in MySQL and PostgreSQL.

Every asset in the doctrine schema has a name. A name consists of either a namespace.local name pair or just a local unqualified name.

The abstraction layer that covers a PostgreSQL schema is the namespace of an database object (asset). A schema can have a name, which will be used as default namespace for the unqualified database objects that are created in the schema.

In the case of MySQL where cross-database queries are allowed this leads to databases being "misinterpreted" as namespaces. This is intentional, however the CREATE/DROP SQL visitors will just filter this queries and do not execute them. Only the queries for the currently connected database are executed.

Table of Contents

Properties

$_name  : string
$_namespace  : string|null
Namespace of the asset. If none isset the default namespace is assumed.
$_quoted  : bool
$_schemaConfig  : SchemaConfig
$_sequences  : array<string|int, Sequence>
$_tables  : array<string|int, Table>
$namespaces  : array<string|int, string>
The namespaces in this schema.

Methods

__clone()  : void
Cloning a Schema triggers a deep clone of all related assets.
__construct()  : mixed
createNamespace()  : Schema
Creates a new namespace.
createSequence()  : Sequence
Creates a new sequence.
createTable()  : Table
Creates a new table.
dropSequence()  : Schema
dropTable()  : Schema
Drops a table from the schema.
getFullQualifiedName()  : string
The normalized name is full-qualified and lower-cased. Lower-casing is actually wrong, but we have to do it to keep our sanity. If you are using database objects that only differentiate in the casing (FOO vs Foo) then you will NOT be able to use Doctrine Schema abstraction.
getMigrateFromSql()  : array<string|int, string>
getMigrateToSql()  : array<string|int, string>
getName()  : string
Returns the name of this schema asset.
getNamespaceName()  : string|null
Gets the namespace name of this asset.
getNamespaces()  : array<string|int, string>
Returns the namespaces of this schema.
getQuotedName()  : string
Gets the quoted representation of this asset but only if it was defined with one. Otherwise return the plain unquoted value as inserted.
getSequence()  : Sequence
getSequences()  : array<string|int, Sequence>
getShortestName()  : string
The shortest name is stripped of the default namespace. All other namespaced elements are returned as full-qualified names.
getTable()  : Table
getTableNames()  : array<string|int, string>
Gets all table names, prefixed with a schema name, even the default one if present.
getTables()  : array<string|int, Table>
Gets all tables of this schema.
hasExplicitForeignKeyIndexes()  : bool
hasNamespace()  : bool
Does this schema have a namespace with the given name?
hasSequence()  : bool
hasTable()  : bool
Does this schema have a table with the given name?
isInDefaultNamespace()  : bool
Is this asset in the default namespace?
isQuoted()  : bool
Checks if this asset's name is quoted.
renameTable()  : Schema
Renames a table.
toDropSql()  : array<int, string>
Return an array of necessary SQL queries to drop the schema on the given platform.
toSql()  : array<int, string>
Returns an array of necessary SQL queries to create the schema on the given platform.
visit()  : void
_addSequence()  : void
_addTable()  : void
_generateIdentifierName()  : string
Generates an identifier from a list of column names obeying a certain string length.
_setName()  : void
Sets the name of this asset.
isIdentifierQuoted()  : bool
Checks if this identifier is quoted.
trimQuotes()  : string
Trim quotes from the identifier.
getFullQualifiedAssetName()  : string
getUnquotedAssetName()  : string
Returns the unquoted representation of a given asset name.
normalizeName()  : string

Properties

$_namespace

Namespace of the asset. If none isset the default namespace is assumed.

protected string|null $_namespace

$_tables

protected array<string|int, Table> $_tables = []

$namespaces

The namespaces in this schema.

private array<string|int, string> $namespaces = []

Methods

__clone()

Cloning a Schema triggers a deep clone of all related assets.

public __clone() : void

__construct()

public __construct([array<string|int, Table$tables = [] ][, array<string|int, Sequence$sequences = [] ][, SchemaConfig|null $schemaConfig = null ][, array<string|int, string> $namespaces = [] ]) : mixed
Parameters
$tables : array<string|int, Table> = []
$sequences : array<string|int, Sequence> = []
$schemaConfig : SchemaConfig|null = null
$namespaces : array<string|int, string> = []
Tags
throws
SchemaException

createNamespace()

Creates a new namespace.

public createNamespace(string $name) : Schema
Parameters
$name : string

The name of the namespace to create.

Tags
throws
SchemaException
Return values
Schema

This schema instance.

createSequence()

Creates a new sequence.

public createSequence(string $name[, int $allocationSize = 1 ][, int $initialValue = 1 ]) : Sequence
Parameters
$name : string
$allocationSize : int = 1
$initialValue : int = 1
Tags
throws
SchemaException
Return values
Sequence

dropSequence()

public dropSequence(string $name) : Schema
Parameters
$name : string
Return values
Schema

getFullQualifiedName()

The normalized name is full-qualified and lower-cased. Lower-casing is actually wrong, but we have to do it to keep our sanity. If you are using database objects that only differentiate in the casing (FOO vs Foo) then you will NOT be able to use Doctrine Schema abstraction.

public getFullQualifiedName(string $defaultNamespaceName) : string

Every non-namespaced element is prefixed with the default namespace name which is passed as argument to this method.

Parameters
$defaultNamespaceName : string
Tags
deprecated

Use getNamespaceName() and getName() instead.

Return values
string

getName()

Returns the name of this schema asset.

public getName() : string
Return values
string

getNamespaceName()

Gets the namespace name of this asset.

public getNamespaceName() : string|null

If NULL is returned this means the default namespace is used.

Return values
string|null

getNamespaces()

Returns the namespaces of this schema.

public getNamespaces() : array<string|int, string>
Return values
array<string|int, string>

A list of namespace names.

getQuotedName()

Gets the quoted representation of this asset but only if it was defined with one. Otherwise return the plain unquoted value as inserted.

public getQuotedName(AbstractPlatform $platform) : string
Parameters
$platform : AbstractPlatform
Return values
string

getShortestName()

The shortest name is stripped of the default namespace. All other namespaced elements are returned as full-qualified names.

public getShortestName(string|null $defaultNamespaceName) : string
Parameters
$defaultNamespaceName : string|null
Return values
string

getTableNames()

Gets all table names, prefixed with a schema name, even the default one if present.

public getTableNames() : array<string|int, string>
Tags
deprecated

Use getTables() and Table::getName() instead.

Return values
array<string|int, string>

getTables()

Gets all tables of this schema.

public getTables() : array<string|int, Table>
Return values
array<string|int, Table>

hasExplicitForeignKeyIndexes()

public hasExplicitForeignKeyIndexes() : bool
Tags
deprecated
Return values
bool

hasNamespace()

Does this schema have a namespace with the given name?

public hasNamespace(string $name) : bool
Parameters
$name : string
Return values
bool

hasSequence()

public hasSequence(string $name) : bool
Parameters
$name : string
Return values
bool

hasTable()

Does this schema have a table with the given name?

public hasTable(string $name) : bool
Parameters
$name : string
Return values
bool

isInDefaultNamespace()

Is this asset in the default namespace?

public isInDefaultNamespace(string $defaultNamespaceName) : bool
Parameters
$defaultNamespaceName : string
Return values
bool

isQuoted()

Checks if this asset's name is quoted.

public isQuoted() : bool
Return values
bool

renameTable()

Renames a table.

public renameTable(string $oldName, string $newName) : Schema
Parameters
$oldName : string
$newName : string
Tags
throws
SchemaException
Return values
Schema

toDropSql()

Return an array of necessary SQL queries to drop the schema on the given platform.

public toDropSql(AbstractPlatform $platform) : array<int, string>
Parameters
$platform : AbstractPlatform
Tags
throws
Exception
Return values
array<int, string>

toSql()

Returns an array of necessary SQL queries to create the schema on the given platform.

public toSql(AbstractPlatform $platform) : array<int, string>
Parameters
$platform : AbstractPlatform
Tags
throws
Exception
Return values
array<int, string>

_generateIdentifierName()

Generates an identifier from a list of column names obeying a certain string length.

protected _generateIdentifierName(array<string|int, string> $columnNames[, string $prefix = '' ][, int $maxSize = 30 ]) : string

This is especially important for Oracle, since it does not allow identifiers larger than 30 chars, however building idents automatically for foreign keys, composite keys or such can easily create very long names.

Parameters
$columnNames : array<string|int, string>
$prefix : string = ''
$maxSize : int = 30
Return values
string

_setName()

Sets the name of this asset.

protected _setName(string $name) : void
Parameters
$name : string

isIdentifierQuoted()

Checks if this identifier is quoted.

protected isIdentifierQuoted(string $identifier) : bool
Parameters
$identifier : string
Return values
bool

trimQuotes()

Trim quotes from the identifier.

protected trimQuotes(string $identifier) : string
Parameters
$identifier : string
Return values
string

getFullQualifiedAssetName()

private getFullQualifiedAssetName(string $name) : string
Parameters
$name : string
Return values
string

getUnquotedAssetName()

Returns the unquoted representation of a given asset name.

private getUnquotedAssetName(string $assetName) : string
Parameters
$assetName : string

Quoted or unquoted representation of an asset name.

Return values
string

        
On this page

Search results