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 MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Doctrine\ORM\Mapping; |
21
|
|
|
|
22
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* A set of rules for determining the physical column, alias and table quotes |
26
|
|
|
* |
27
|
|
|
* @since 2.3 |
28
|
|
|
* @author Fabio B. Silva <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
class DefaultQuoteStrategy implements QuoteStrategy |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
1470 |
|
public function getColumnName($fieldName, ClassMetadata $class, AbstractPlatform $platform) |
36
|
|
|
{ |
37
|
1470 |
|
return isset($class->fieldMappings[$fieldName]['quoted']) |
38
|
24 |
|
? $platform->quoteIdentifier($class->fieldMappings[$fieldName]['columnName']) |
39
|
1470 |
|
: $class->fieldMappings[$fieldName]['columnName']; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
* |
45
|
|
|
* @todo Table names should be computed in DBAL depending on the platform |
46
|
|
|
*/ |
47
|
1480 |
|
public function getTableName(ClassMetadata $class, AbstractPlatform $platform) |
48
|
|
|
{ |
49
|
1480 |
|
$tableName = $class->table['name']; |
50
|
|
|
|
51
|
1480 |
|
if ( ! empty($class->table['schema'])) { |
52
|
7 |
|
$tableName = $class->table['schema'] . '.' . $class->table['name']; |
53
|
|
|
|
54
|
7 |
|
if ( ! $platform->supportsSchemas() && $platform->canEmulateSchemas()) { |
55
|
7 |
|
$tableName = $class->table['schema'] . '__' . $class->table['name']; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
1480 |
|
return isset($class->table['quoted']) |
60
|
27 |
|
? $platform->quoteIdentifier($tableName) |
61
|
1480 |
|
: $tableName; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
6 |
|
public function getSequenceName(array $definition, ClassMetadata $class, AbstractPlatform $platform) |
68
|
|
|
{ |
69
|
6 |
|
return isset($definition['quoted']) |
70
|
|
|
? $platform->quoteIdentifier($definition['sequenceName']) |
71
|
6 |
|
: $definition['sequenceName']; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
1102 |
|
public function getJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform) |
78
|
|
|
{ |
79
|
1102 |
|
return isset($joinColumn['quoted']) |
80
|
14 |
|
? $platform->quoteIdentifier($joinColumn['name']) |
81
|
1102 |
|
: $joinColumn['name']; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
594 |
|
public function getReferencedJoinColumnName(array $joinColumn, ClassMetadata $class, AbstractPlatform $platform) |
88
|
|
|
{ |
89
|
594 |
|
return isset($joinColumn['quoted']) |
90
|
9 |
|
? $platform->quoteIdentifier($joinColumn['referencedColumnName']) |
91
|
594 |
|
: $joinColumn['referencedColumnName']; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritdoc} |
96
|
|
|
*/ |
97
|
411 |
|
public function getJoinTableName(array $association, ClassMetadata $class, AbstractPlatform $platform) |
98
|
|
|
{ |
99
|
411 |
|
$schema = ''; |
100
|
|
|
|
101
|
411 |
|
if (isset($association['joinTable']['schema'])) { |
102
|
2 |
|
$schema = $association['joinTable']['schema']; |
103
|
2 |
|
$schema .= ! $platform->supportsSchemas() && $platform->canEmulateSchemas() ? '__' : '.'; |
104
|
|
|
} |
105
|
|
|
|
106
|
411 |
|
$tableName = $association['joinTable']['name']; |
107
|
|
|
|
108
|
411 |
|
if (isset($association['joinTable']['quoted'])) { |
109
|
9 |
|
$tableName = $platform->quoteIdentifier($tableName); |
110
|
|
|
} |
111
|
|
|
|
112
|
411 |
|
return $schema . $tableName; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* {@inheritdoc} |
117
|
|
|
*/ |
118
|
388 |
|
public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform $platform) |
119
|
|
|
{ |
120
|
388 |
|
$quotedColumnNames = []; |
121
|
|
|
|
122
|
388 |
|
foreach ($class->identifier as $fieldName) { |
123
|
388 |
|
if (isset($class->fieldMappings[$fieldName])) { |
124
|
384 |
|
$quotedColumnNames[] = $this->getColumnName($fieldName, $class, $platform); |
125
|
|
|
|
126
|
384 |
|
continue; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// Association defined as Id field |
130
|
8 |
|
$joinColumns = $class->associationMappings[$fieldName]['joinColumns']; |
131
|
8 |
|
$assocQuotedColumnNames = array_map( |
132
|
|
|
function ($joinColumn) use ($platform) |
133
|
|
|
{ |
134
|
8 |
|
return isset($joinColumn['quoted']) |
135
|
1 |
|
? $platform->quoteIdentifier($joinColumn['name']) |
136
|
8 |
|
: $joinColumn['name']; |
137
|
8 |
|
}, |
138
|
8 |
|
$joinColumns |
139
|
|
|
); |
140
|
|
|
|
141
|
8 |
|
$quotedColumnNames = array_merge($quotedColumnNames, $assocQuotedColumnNames); |
142
|
|
|
} |
143
|
|
|
|
144
|
388 |
|
return $quotedColumnNames; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* {@inheritdoc} |
149
|
|
|
*/ |
150
|
1166 |
|
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null) |
151
|
|
|
{ |
152
|
|
|
// 1 ) Concatenate column name and counter |
153
|
|
|
// 2 ) Trim the column alias to the maximum identifier length of the platform. |
154
|
|
|
// If the alias is to long, characters are cut off from the beginning. |
155
|
|
|
// 3 ) Strip non alphanumeric characters |
156
|
|
|
// 4 ) Prefix with "_" if the result its numeric |
157
|
1166 |
|
$columnName = $columnName . '_' . $counter; |
158
|
1166 |
|
$columnName = substr($columnName, -$platform->getMaxIdentifierLength()); |
159
|
1166 |
|
$columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName); |
160
|
1166 |
|
$columnName = is_numeric($columnName) ? '_' . $columnName : $columnName; |
161
|
|
|
|
162
|
1166 |
|
return $platform->getSQLResultCasing($columnName); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|