MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Schema.php
Ir para a documentação deste ficheiro.
1
<?php
2
/*
3
* $Id$
4
*
5
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
*
17
* This software consists of voluntary contributions made by many individuals
18
* and is licensed under the LGPL. For more information, see
19
* <http://www.doctrine-project.org>.
20
*/
21
22
namespace
Doctrine\DBAL\Schema
;
23
24
use
Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector
;
25
use
Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector
;
26
use
Doctrine\DBAL\Schema\Visitor\Visitor
;
27
37
class
Schema
extends
AbstractAsset
38
{
42
protected
$_tables
= array();
43
47
protected
$_sequences
= array();
48
52
protected
$_schemaConfig
=
false
;
53
61
public
function
__construct
(array $tables=array(), array $sequences=array(),
SchemaConfig
$schemaConfig=
null
)
62
{
63
if
($schemaConfig ==
null
) {
64
$schemaConfig =
new
SchemaConfig
();
65
}
66
$this->_schemaConfig = $schemaConfig;
67
68
foreach
($tables AS $table) {
69
$this->
_addTable
($table);
70
}
71
foreach
($sequences AS $sequence) {
72
$this->
_addSequence
($sequence);
73
}
74
}
75
79
public
function
hasExplicitForeignKeyIndexes
()
80
{
81
return
$this->_schemaConfig->hasExplicitForeignKeyIndexes();
82
}
83
87
protected
function
_addTable
(
Table
$table)
88
{
89
$tableName = strtolower($table->
getName
());
90
if
(isset($this->_tables[$tableName])) {
91
throw
SchemaException::tableAlreadyExists
($tableName);
92
}
93
94
$this->_tables[$tableName] = $table;
95
$table->
setSchemaConfig
($this->_schemaConfig);
96
}
97
101
protected
function
_addSequence
(
Sequence
$sequence)
102
{
103
$seqName = strtolower($sequence->
getName
());
104
if
(isset($this->_sequences[$seqName])) {
105
throw
SchemaException::sequenceAlreadyExists
($seqName);
106
}
107
$this->_sequences[$seqName] = $sequence;
108
}
109
115
public
function
getTables
()
116
{
117
return
$this->_tables
;
118
}
119
124
public
function
getTable
($tableName)
125
{
126
$tableName = strtolower($tableName);
127
if
(!isset($this->_tables[$tableName])) {
128
throw
SchemaException::tableDoesNotExist
($tableName);
129
}
130
131
return
$this->_tables[$tableName];
132
}
133
140
public
function
hasTable
($tableName)
141
{
142
$tableName = strtolower($tableName);
143
return
isset($this->_tables[$tableName]);
144
}
145
150
public
function
hasSequence
($sequenceName)
151
{
152
$sequenceName = strtolower($sequenceName);
153
return
isset($this->_sequences[$sequenceName]);
154
}
155
161
public
function
getSequence
($sequenceName)
162
{
163
$sequenceName = strtolower($sequenceName);
164
if
(!$this->
hasSequence
($sequenceName)) {
165
throw
SchemaException::sequenceDoesNotExist
($sequenceName);
166
}
167
return
$this->_sequences[$sequenceName];
168
}
169
173
public
function
getSequences
()
174
{
175
return
$this->_sequences
;
176
}
177
184
public
function
createTable
($tableName)
185
{
186
$table =
new
Table
($tableName);
187
$this->
_addTable
($table);
188
return
$table;
189
}
190
198
public
function
renameTable
($oldTableName, $newTableName)
199
{
200
$table = $this->
getTable
($oldTableName);
201
$table->_setName($newTableName);
202
203
$this->
dropTable
($oldTableName);
204
$this->
_addTable
($table);
205
return
$this;
206
}
207
214
public
function
dropTable
($tableName)
215
{
216
$tableName = strtolower($tableName);
217
$table = $this->
getTable
($tableName);
218
unset($this->_tables[$tableName]);
219
return
$this;
220
}
221
230
public
function
createSequence
($sequenceName, $allocationSize=1, $initialValue=1)
231
{
232
$seq =
new
Sequence
($sequenceName, $allocationSize, $initialValue);
233
$this->
_addSequence
($seq);
234
return
$seq;
235
}
236
241
public
function
dropSequence
($sequenceName)
242
{
243
$sequenceName = strtolower($sequenceName);
244
unset($this->_sequences[$sequenceName]);
245
return
$this;
246
}
247
254
public
function
toSql
(\Doctrine\DBAL\Platforms\
AbstractPlatform
$platform)
255
{
256
$sqlCollector =
new
CreateSchemaSqlCollector
($platform);
257
$this->
visit
($sqlCollector);
258
259
return
$sqlCollector->getQueries();
260
}
261
268
public
function
toDropSql
(\Doctrine\DBAL\Platforms\
AbstractPlatform
$platform)
269
{
270
$dropSqlCollector =
new
DropSchemaSqlCollector
($platform);
271
$this->
visit
($dropSqlCollector);
272
273
return
$dropSqlCollector->getQueries();
274
}
275
280
public
function
getMigrateToSql
(
Schema
$toSchema, \Doctrine\DBAL\Platforms\
AbstractPlatform
$platform)
281
{
282
$comparator =
new
Comparator
();
283
$schemaDiff = $comparator->compare($this, $toSchema);
284
return
$schemaDiff->toSql($platform);
285
}
286
291
public
function
getMigrateFromSql
(
Schema
$fromSchema, \Doctrine\DBAL\Platforms\
AbstractPlatform
$platform)
292
{
293
$comparator =
new
Comparator
();
294
$schemaDiff = $comparator->compare($fromSchema, $this);
295
return
$schemaDiff->toSql($platform);
296
}
297
301
public
function
visit
(
Visitor
$visitor)
302
{
303
$visitor->
acceptSchema
($this);
304
305
foreach
($this->_tables AS $table) {
306
$table->visit($visitor);
307
}
308
foreach
($this->_sequences AS $sequence) {
309
$sequence->visit($visitor);
310
}
311
}
312
318
public
function
__clone
()
319
{
320
foreach
($this->_tables AS $k => $table) {
321
$this->_tables[$k] = clone $table;
322
}
323
foreach
($this->_sequences AS $k => $sequence) {
324
$this->_sequences[$k] = clone $sequence;
325
}
326
}
327
}
Doctrine\DBAL\Platforms\AbstractPlatform
Definição
AbstractPlatform.php:47
Doctrine\DBAL\Schema\AbstractAsset
Definição
AbstractAsset.php:39
Doctrine\DBAL\Schema\AbstractAsset\getName
getName()
Definição
AbstractAsset.php:72
Doctrine\DBAL\Schema\Comparator
Definição
Comparator.php:34
Doctrine\DBAL\Schema\SchemaConfig
Definição
SchemaConfig.php:34
Doctrine\DBAL\Schema\SchemaException\tableAlreadyExists
static tableAlreadyExists($tableName)
Definição
SchemaException.php:68
Doctrine\DBAL\Schema\SchemaException\sequenceDoesNotExist
static sequenceDoesNotExist($sequenceName)
Definição
SchemaException.php:99
Doctrine\DBAL\Schema\SchemaException\sequenceAlreadyExists
static sequenceAlreadyExists($sequenceName)
Definição
SchemaException.php:90
Doctrine\DBAL\Schema\SchemaException\tableDoesNotExist
static tableDoesNotExist($tableName)
Definição
SchemaException.php:22
Doctrine\DBAL\Schema\Schema
Definição
Schema.php:38
Doctrine\DBAL\Schema\Schema\$_tables
$_tables
Definição
Schema.php:42
Doctrine\DBAL\Schema\Schema\dropTable
dropTable($tableName)
Definição
Schema.php:214
Doctrine\DBAL\Schema\Schema\toDropSql
toDropSql(\Doctrine\DBAL\Platforms\AbstractPlatform $platform)
Definição
Schema.php:268
Doctrine\DBAL\Schema\Schema\$_sequences
$_sequences
Definição
Schema.php:47
Doctrine\DBAL\Schema\Schema\$_schemaConfig
$_schemaConfig
Definição
Schema.php:52
Doctrine\DBAL\Schema\Schema\_addTable
_addTable(Table $table)
Definição
Schema.php:87
Doctrine\DBAL\Schema\Schema\hasExplicitForeignKeyIndexes
hasExplicitForeignKeyIndexes()
Definição
Schema.php:79
Doctrine\DBAL\Schema\Schema\createTable
createTable($tableName)
Definição
Schema.php:184
Doctrine\DBAL\Schema\Schema\getMigrateToSql
getMigrateToSql(Schema $toSchema, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
Definição
Schema.php:280
Doctrine\DBAL\Schema\Schema\getSequences
getSequences()
Definição
Schema.php:173
Doctrine\DBAL\Schema\Schema\createSequence
createSequence($sequenceName, $allocationSize=1, $initialValue=1)
Definição
Schema.php:230
Doctrine\DBAL\Schema\Schema\getTables
getTables()
Definição
Schema.php:115
Doctrine\DBAL\Schema\Schema\visit
visit(Visitor $visitor)
Definição
Schema.php:301
Doctrine\DBAL\Schema\Schema\renameTable
renameTable($oldTableName, $newTableName)
Definição
Schema.php:198
Doctrine\DBAL\Schema\Schema\__construct
__construct(array $tables=array(), array $sequences=array(), SchemaConfig $schemaConfig=null)
Definição
Schema.php:61
Doctrine\DBAL\Schema\Schema\hasTable
hasTable($tableName)
Definição
Schema.php:140
Doctrine\DBAL\Schema\Schema\hasSequence
hasSequence($sequenceName)
Definição
Schema.php:150
Doctrine\DBAL\Schema\Schema\toSql
toSql(\Doctrine\DBAL\Platforms\AbstractPlatform $platform)
Definição
Schema.php:254
Doctrine\DBAL\Schema\Schema\getMigrateFromSql
getMigrateFromSql(Schema $fromSchema, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
Definição
Schema.php:291
Doctrine\DBAL\Schema\Schema\dropSequence
dropSequence($sequenceName)
Definição
Schema.php:241
Doctrine\DBAL\Schema\Schema\getSequence
getSequence($sequenceName)
Definição
Schema.php:161
Doctrine\DBAL\Schema\Schema\getTable
getTable($tableName)
Definição
Schema.php:124
Doctrine\DBAL\Schema\Schema\__clone
__clone()
Definição
Schema.php:318
Doctrine\DBAL\Schema\Schema\_addSequence
_addSequence(Sequence $sequence)
Definição
Schema.php:101
Doctrine\DBAL\Schema\Sequence
Definição
Sequence.php:36
Doctrine\DBAL\Schema\Table
Definição
Table.php:38
Doctrine\DBAL\Schema\Table\setSchemaConfig
setSchemaConfig(SchemaConfig $schemaConfig)
Definição
Table.php:110
Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector
Definição
CreateSchemaSqlCollector.php:34
Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector
Definição
DropSchemaSqlCollector.php:43
Doctrine\DBAL\Schema\Visitor\Visitor
Definição
Visitor.php:43
Doctrine\DBAL\Schema\Visitor\Visitor\acceptSchema
acceptSchema(Schema $schema)
Doctrine\DBAL\Schema
Definição
AbstractAsset.php:22
classes
extensions
doctrine-dbal
Doctrine
DBAL
Schema
Schema.php
Gerado por
1.10.0