1 | <?php |
||
18 | class MySQLDriver implements DriverInterface |
||
19 | { |
||
20 | const FOREIGN_QUERY = 'SELECT COLUMN_NAME as "column", REFERENCED_COLUMN_NAME as "referenced_column",' . |
||
21 | 'CONCAT(REFERENCED_TABLE_SCHEMA, ".", REFERENCED_TABLE_NAME) as "referenced_table"' . |
||
22 | 'FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE ' . |
||
23 | 'WHERE CONSTRAINT_SCHEMA = "%s" AND TABLE_NAME = "%s";'; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $database; |
||
29 | |||
30 | /** |
||
31 | * @var \PDO |
||
32 | */ |
||
33 | protected $pdo; |
||
34 | |||
35 | 105 | /** |
|
36 | * Initializes the driver instance. |
||
37 | 105 | * |
|
38 | * @param \PDO $pdo |
||
39 | 105 | * @param string $database |
|
40 | */ |
||
41 | 105 | public function __construct(\PDO $pdo, $database) |
|
49 | |||
50 | 84 | /** |
|
51 | * Returns an array of Column instances from a table. |
||
52 | 84 | * |
|
53 | * @param string $table |
||
54 | * @return \Rougin\Describe\Column[] |
||
55 | */ |
||
56 | public function columns($table) |
||
60 | |||
61 | /** |
||
62 | 48 | * Returns an array of Column instances from a table. |
|
63 | * NOTE: To be removed in v2.0.0. Use columns() instead. |
||
64 | 48 | * |
|
65 | * @param string $table |
||
66 | * @return \Rougin\Describe\Column[] |
||
67 | */ |
||
68 | public function getColumns($table) |
||
72 | |||
73 | /** |
||
74 | 42 | * Returns an array of Column instances from a table. |
|
75 | * NOTE: To be removed in v2.0.0. Use getColumns() instead. |
||
76 | 42 | * |
|
77 | * @param string $table |
||
78 | * @return \Rougin\Describe\Column[] |
||
79 | */ |
||
80 | public function getTable($table) |
||
84 | |||
85 | 6 | /** |
|
86 | * Returns an array of table names. |
||
87 | 6 | * NOTE: To be removed in v2.0.0. Use tables() instead. |
|
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | public function getTableNames() |
||
95 | |||
96 | 3 | /** |
|
97 | * Returns an array of table names. |
||
98 | 3 | * NOTE: To be removed in v2.0.0. Use getTableNames() instead. |
|
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | public function showTables() |
||
106 | 12 | ||
107 | /** |
||
108 | 12 | * Returns an array of Table instances. |
|
109 | * |
||
110 | * @return \Rougin\Describe\Table[] |
||
111 | */ |
||
112 | public function tables() |
||
116 | |||
117 | /** |
||
118 | * Prepares the defined columns. |
||
119 | 78 | * |
|
120 | * @param \Rougin\Describe\Column $column |
||
121 | 78 | * @param string $table |
|
122 | * @param mixed $row |
||
123 | 78 | * @return \Rougin\Describe\Column |
|
124 | */ |
||
125 | 78 | protected function column(Column $column, $table, $row) |
|
147 | |||
148 | /** |
||
149 | * Sets the properties of a column if it does exists. |
||
150 | 78 | * |
|
151 | * @param string $name |
||
152 | * @param mixed $row |
||
153 | 78 | * @param \Rougin\Describe\Column $column |
|
154 | 78 | * @return \Rougin\Describe\Column |
|
155 | 78 | */ |
|
156 | protected function foreign($name, $row, Column $column) |
||
178 | |||
179 | /** |
||
180 | * Returns an array of table names or Table instances. |
||
181 | * NOTE: To be removed in v2.0.0. Move to tables() instead. |
||
182 | * |
||
183 | * @param boolean $instance |
||
184 | 18 | * @param array $tables |
|
185 | * @return array|\Rougin\Describe\Table[] |
||
186 | 18 | */ |
|
187 | protected function items($instance = false, $tables = array()) |
||
202 | |||
203 | /** |
||
204 | * Sets the key of a column. |
||
205 | * |
||
206 | * @param mixed $row |
||
207 | 78 | * @param \Rougin\Describe\Column $column |
|
208 | * @return \Rougin\Describe\Column |
||
209 | 78 | */ |
|
210 | 78 | protected function keys($row, Column $column) |
|
231 | |||
232 | /** |
||
233 | * Returns the list of columns based on a query. |
||
234 | * |
||
235 | * @param string $table |
||
236 | 78 | * @param string $query |
|
237 | * @param array $columns |
||
238 | 78 | * @return \Rougin\Describe\Column[] |
|
239 | */ |
||
240 | 78 | protected function query($table, $query, $columns = array()) |
|
262 | |||
263 | /** |
||
264 | * Sets the properties of a column. |
||
265 | * |
||
266 | * @param mixed $row |
||
267 | * @param \Rougin\Describe\Column $column |
||
268 | * @return \Rougin\Describe\Column |
||
269 | */ |
||
270 | protected function properties($row, Column $column) |
||
280 | |||
281 | /** |
||
282 | * Strips the table schema from the table name. |
||
283 | * |
||
284 | * @param string $table |
||
285 | * @return string |
||
286 | */ |
||
287 | protected function strip($table) |
||
295 | } |
||
296 |