MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Index.php
Ir para a documentação deste ficheiro.
1
<?php
2
/*
3
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
*
15
* This software consists of voluntary contributions made by many individuals
16
* and is licensed under the LGPL. For more information, see
17
* <http://www.doctrine-project.org>.
18
*/
19
20
namespace
Doctrine\DBAL\Schema
;
21
22
use
Doctrine\DBAL\Schema\Visitor\Visitor
;
23
24
class
Index
extends
AbstractAsset
implements
Constraint
25
{
29
protected
$_columns
;
30
34
protected
$_isUnique
=
false
;
35
39
protected
$_isPrimary
=
false
;
40
47
public
function
__construct
($indexName, array $columns, $isUnique=
false
, $isPrimary=
false
)
48
{
49
$isUnique = ($isPrimary)?
true
:$isUnique;
50
51
$this->
_setName
($indexName);
52
$this->_isUnique = $isUnique;
53
$this->_isPrimary = $isPrimary;
54
55
foreach
($columns AS $column) {
56
$this->
_addColumn
($column);
57
}
58
}
59
63
protected
function
_addColumn
($column)
64
{
65
if
(is_string($column)) {
66
$this->_columns[] = $column;
67
}
else
{
68
throw
new \InvalidArgumentException(
"Expecting a string as Index Column"
);
69
}
70
}
71
75
public
function
getColumns
()
76
{
77
return
$this->_columns
;
78
}
79
83
public
function
isUnique
()
84
{
85
return
$this->_isUnique
;
86
}
87
91
public
function
isPrimary
()
92
{
93
return
$this->_isPrimary
;
94
}
95
101
public
function
hasColumnAtPosition
($columnName, $pos=0)
102
{
103
$columnName = strtolower($columnName);
104
$indexColumns = \array_map(
'strtolower'
, $this->
getColumns
());
105
return \array_search($columnName, $indexColumns) === $pos;
106
}
107
114
public
function
spansColumns
(array $columnNames)
115
{
116
$sameColumns =
true
;
117
for
($i = 0; $i < count($this->_columns); $i++) {
118
if
(!isset($columnNames[$i]) || strtolower($this->_columns[$i]) != strtolower($columnNames[$i])) {
119
$sameColumns =
false
;
120
}
121
}
122
return
$sameColumns;
123
}
124
131
public
function
isFullfilledBy
(
Index
$other)
132
{
133
// allow the other index to be equally large only. It being larger is an option
134
// but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)
135
if
(count($other->
getColumns
()) != count($this->
getColumns
())) {
136
return
false
;
137
}
138
139
// Check if columns are the same, and even in the same order
140
$sameColumns = $this->
spansColumns
($other->
getColumns
());
141
142
if
($sameColumns) {
143
if
(!$this->
isUnique
() && !$this->
isPrimary
()) {
144
// this is a special case: If the current key is neither primary or unique, any uniqe or
145
// primary key will always have the same effect for the index and there cannot be any constraint
146
// overlaps. This means a primary or unique index can always fullfill the requirements of just an
147
// index that has no constraints.
148
return
true
;
149
}
else
if
($other->
isPrimary
() != $this->isPrimary()) {
150
return
false
;
151
}
else
if
($other->
isUnique
() != $this->isUnique()) {
152
return
false
;
153
}
154
return
true
;
155
}
156
return
false
;
157
}
158
165
public
function
overrules
(
Index
$other)
166
{
167
if
($other->
isPrimary
() || $other->
isUnique
()) {
168
return
false
;
169
}
170
171
if
($this->
spansColumns
($other->
getColumns
()) && ($this->isPrimary() || $this->isUnique())) {
172
return
true
;
173
}
174
return
false
;
175
}
176
}
Doctrine\DBAL\Schema\AbstractAsset
Definição
AbstractAsset.php:39
Doctrine\DBAL\Schema\AbstractAsset\_setName
_setName($name)
Definição
AbstractAsset.php:52
Doctrine\DBAL\Schema\Index
Definição
Index.php:25
Doctrine\DBAL\Schema\Index\__construct
__construct($indexName, array $columns, $isUnique=false, $isPrimary=false)
Definição
Index.php:47
Doctrine\DBAL\Schema\Index\isPrimary
isPrimary()
Definição
Index.php:91
Doctrine\DBAL\Schema\Index\spansColumns
spansColumns(array $columnNames)
Definição
Index.php:114
Doctrine\DBAL\Schema\Index\overrules
overrules(Index $other)
Definição
Index.php:165
Doctrine\DBAL\Schema\Index\isFullfilledBy
isFullfilledBy(Index $other)
Definição
Index.php:131
Doctrine\DBAL\Schema\Index\$_columns
$_columns
Definição
Index.php:29
Doctrine\DBAL\Schema\Index\getColumns
getColumns()
Definição
Index.php:75
Doctrine\DBAL\Schema\Index\$_isPrimary
$_isPrimary
Definição
Index.php:39
Doctrine\DBAL\Schema\Index\$_isUnique
$_isUnique
Definição
Index.php:34
Doctrine\DBAL\Schema\Index\hasColumnAtPosition
hasColumnAtPosition($columnName, $pos=0)
Definição
Index.php:101
Doctrine\DBAL\Schema\Index\isUnique
isUnique()
Definição
Index.php:83
Doctrine\DBAL\Schema\Index\_addColumn
_addColumn($column)
Definição
Index.php:63
Doctrine\DBAL\Schema\Constraint
Definição
Constraint.php:34
Doctrine\DBAL\Schema\Visitor\Visitor
Definição
Visitor.php:43
Doctrine\DBAL\Schema
Definição
AbstractAsset.php:22
classes
extensions
doctrine-dbal
Doctrine
DBAL
Schema
Index.php
Gerado por
1.10.0