MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
MySqlSchemaManager.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
20namespace Doctrine\DBAL\Schema;
21
34{
35 protected function _getPortableViewDefinition($view)
36 {
37 return new View($view['TABLE_NAME'], $view['VIEW_DEFINITION']);
38 }
39
40 protected function _getPortableTableDefinition($table)
41 {
42 return array_shift($table);
43 }
44
45 protected function _getPortableUserDefinition($user)
46 {
47 return array(
48 'user' => $user['User'],
49 'password' => $user['Password'],
50 );
51 }
52
53 protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
54 {
55 foreach($tableIndexes AS $k => $v) {
56 $v = array_change_key_case($v, CASE_LOWER);
57 if($v['key_name'] == 'PRIMARY') {
58 $v['primary'] = true;
59 } else {
60 $v['primary'] = false;
61 }
62 $tableIndexes[$k] = $v;
63 }
64
65 return parent::_getPortableTableIndexesList($tableIndexes, $tableName);
66 }
67
68 protected function _getPortableSequenceDefinition($sequence)
69 {
70 return end($sequence);
71 }
72
73 protected function _getPortableDatabaseDefinition($database)
74 {
75 return $database['Database'];
76 }
77
86 protected function _getPortableTableColumnDefinition($tableColumn)
87 {
88 $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
89
90 $dbType = strtolower($tableColumn['type']);
91 $dbType = strtok($dbType, '(), ');
92 if (isset($tableColumn['length'])) {
93 $length = $tableColumn['length'];
94 $decimal = '';
95 } else {
96 $length = strtok('(), ');
97 $decimal = strtok('(), ') ? strtok('(), '):null;
98 }
99 $type = array();
100 $unsigned = $fixed = null;
101
102 if ( ! isset($tableColumn['name'])) {
103 $tableColumn['name'] = '';
104 }
105
106 $scale = null;
107 $precision = null;
108
109 $type = $this->_platform->getDoctrineTypeMapping($dbType);
110 switch ($dbType) {
111 case 'char':
112 $fixed = true;
113 break;
114 case 'float':
115 case 'double':
116 case 'real':
117 case 'numeric':
118 case 'decimal':
119 if(preg_match('([A-Za-z]+\‍(([0-9]+)\,([0-9]+)\‍))', $tableColumn['type'], $match)) {
120 $precision = $match[1];
121 $scale = $match[2];
122 $length = null;
123 }
124 break;
125 case 'tinyint':
126 case 'smallint':
127 case 'mediumint':
128 case 'int':
129 case 'integer':
130 case 'bigint':
131 case 'tinyblob':
132 case 'mediumblob':
133 case 'longblob':
134 case 'blob':
135 case 'binary':
136 case 'varbinary':
137 case 'year':
138 $length = null;
139 break;
140 }
141
142 $length = ((int) $length == 0) ? null : (int) $length;
143 $def = array(
144 'type' => $type,
145 'length' => $length,
146 'unsigned' => (bool) $unsigned,
147 'fixed' => (bool) $fixed
148 );
149
150 $options = array(
151 'length' => $length,
152 'unsigned' => (bool)$unsigned,
153 'fixed' => (bool)$fixed,
154 'default' => $tableColumn['default'],
155 'notnull' => (bool) ($tableColumn['null'] != 'YES'),
156 'scale' => null,
157 'precision' => null,
158 'autoincrement' => (bool) (strpos($tableColumn['extra'], 'auto_increment') !== false),
159 );
160
161 if ($scale !== null && $precision !== null) {
162 $options['scale'] = $scale;
163 $options['precision'] = $precision;
164 }
165
166 return new Column($tableColumn['field'], \Doctrine\DBAL\Types\Type::getType($type), $options);
167 }
168
169 public function _getPortableTableForeignKeyDefinition($tableForeignKey)
170 {
171 $tableForeignKey = array_change_key_case($tableForeignKey, CASE_LOWER);
172
173 if (!isset($tableForeignKey['delete_rule']) || $tableForeignKey['delete_rule'] == "RESTRICT") {
174 $tableForeignKey['delete_rule'] = null;
175 }
176 if (!isset($tableForeignKey['update_rule']) || $tableForeignKey['update_rule'] == "RESTRICT") {
177 $tableForeignKey['update_rule'] = null;
178 }
179
180 return new ForeignKeyConstraint(
181 (array)$tableForeignKey['column_name'],
182 $tableForeignKey['referenced_table_name'],
183 (array)$tableForeignKey['referenced_column_name'],
184 $tableForeignKey['constraint_name'],
185 array(
186 'onUpdate' => $tableForeignKey['update_rule'],
187 'onDelete' => $tableForeignKey['delete_rule'],
188 )
189 );
190 }
191}
_getPortableTableIndexesList($tableIndexes, $tableName=null)