1 | <?php |
||
18 | class MySQLDriver implements DriverInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $database; |
||
24 | |||
25 | /** |
||
26 | * @var \PDO |
||
27 | */ |
||
28 | protected $pdo; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $script = ''; |
||
34 | |||
35 | /** |
||
36 | * Initializes the driver instance. |
||
37 | * |
||
38 | * @param \PDO $pdo |
||
39 | * @param string $database |
||
40 | */ |
||
41 | 105 | public function __construct(\PDO $pdo, $database) |
|
42 | { |
||
43 | 105 | $this->database = $database; |
|
44 | |||
45 | 105 | $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); |
|
46 | |||
47 | 105 | $this->pdo = $pdo; |
|
48 | |||
49 | 105 | $this->script = 'SELECT COLUMN_NAME as "column", REFERENCED_COLUMN_NAME as ' . |
|
50 | 105 | '"referenced_column", CONCAT(REFERENCED_TABLE_SCHEMA, ".", ' . |
|
51 | 105 | 'REFERENCED_TABLE_NAME) as "referenced_table" FROM INFORMATION_SCHEMA' . |
|
52 | 105 | '.KEY_COLUMN_USAGE WHERE CONSTRAINT_SCHEMA = "%s" AND TABLE_NAME = "%s";'; |
|
53 | 105 | } |
|
54 | |||
55 | /** |
||
56 | * Returns an array of Column instances from a table. |
||
57 | * |
||
58 | * @param string $table |
||
59 | * @return \Rougin\Describe\Column[] |
||
60 | */ |
||
61 | 84 | public function columns($table) |
|
65 | |||
66 | /** |
||
67 | * Returns an array of Column instances from a table. |
||
68 | * NOTE: To be removed in v2.0.0. Use columns() instead. |
||
69 | * |
||
70 | * @param string $table |
||
71 | * @return \Rougin\Describe\Column[] |
||
72 | */ |
||
73 | 48 | public function getColumns($table) |
|
77 | |||
78 | /** |
||
79 | * Returns an array of Column instances from a table. |
||
80 | * NOTE: To be removed in v2.0.0. Use getColumns() instead. |
||
81 | * |
||
82 | * @param string $table |
||
83 | * @return \Rougin\Describe\Column[] |
||
84 | */ |
||
85 | 42 | public function getTable($table) |
|
89 | |||
90 | /** |
||
91 | * Returns an array of table names. |
||
92 | * NOTE: To be removed in v2.0.0. Use tables() instead. |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | 6 | public function getTableNames() |
|
100 | |||
101 | /** |
||
102 | * Returns an array of table names. |
||
103 | * NOTE: To be removed in v2.0.0. Use getTableNames() instead. |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | 3 | public function showTables() |
|
111 | |||
112 | /** |
||
113 | * Returns an array of Table instances. |
||
114 | * |
||
115 | * @return \Rougin\Describe\Table[] |
||
116 | */ |
||
117 | 12 | public function tables() |
|
121 | |||
122 | /** |
||
123 | * Prepares the defined columns. |
||
124 | * |
||
125 | * @param \Rougin\Describe\Column $column |
||
126 | * @param string $table |
||
127 | * @param mixed $row |
||
128 | * @return \Rougin\Describe\Column |
||
129 | */ |
||
130 | 78 | protected function column(Column $column, $table, $row) |
|
152 | |||
153 | /** |
||
154 | * Sets the properties of a column if it does exists. |
||
155 | * |
||
156 | * @param string $name |
||
157 | * @param mixed $row |
||
158 | * @param \Rougin\Describe\Column $column |
||
159 | * @return \Rougin\Describe\Column |
||
160 | */ |
||
161 | 78 | protected function foreign($name, $row, Column $column) |
|
183 | |||
184 | /** |
||
185 | * Returns an array of table names or Table instances. |
||
186 | * NOTE: To be removed in v2.0.0. Move to tables() instead. |
||
187 | * |
||
188 | * @param boolean $instance |
||
189 | * @param array $tables |
||
190 | * @return array|\Rougin\Describe\Table[] |
||
191 | */ |
||
192 | 18 | protected function items($instance = false, $tables = array()) |
|
207 | |||
208 | /** |
||
209 | * Sets the key of a column. |
||
210 | * |
||
211 | * @param mixed $row |
||
212 | * @param \Rougin\Describe\Column $column |
||
213 | * @return \Rougin\Describe\Column |
||
214 | */ |
||
215 | 78 | protected function keys($row, Column $column) |
|
236 | |||
237 | /** |
||
238 | * Returns the list of columns based on a query. |
||
239 | * |
||
240 | * @param string $table |
||
241 | * @param string $query |
||
242 | * @param array $columns |
||
243 | * @return \Rougin\Describe\Column[] |
||
244 | */ |
||
245 | 126 | protected function query($table, $query, $columns = array()) |
|
267 | |||
268 | /** |
||
269 | * Sets the properties of a column. |
||
270 | * |
||
271 | * @param mixed $row |
||
272 | * @param \Rougin\Describe\Column $column |
||
273 | * @return \Rougin\Describe\Column |
||
274 | */ |
||
275 | 78 | protected function properties($row, Column $column) |
|
285 | |||
286 | /** |
||
287 | * Strips the table schema from the table name. |
||
288 | * |
||
289 | * @param string $table |
||
290 | * @return string |
||
291 | */ |
||
292 | 78 | protected function strip($table) |
|
300 | } |
||
301 |