|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Describe\Driver; |
|
4
|
|
|
|
|
5
|
|
|
use PDO; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* CodeIgniter Driver |
|
9
|
|
|
* |
|
10
|
|
|
* A database driver specifically used for CodeIgniter. |
|
11
|
|
|
* |
|
12
|
|
|
* @package Describe |
|
13
|
|
|
* @category Driver |
|
14
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class CodeIgniterDriver implements DriverInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $connection; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $database; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param array $database |
|
30
|
|
|
* @param string $connection |
|
31
|
|
|
*/ |
|
32
|
9 |
|
public function __construct(array $database, $connection = 'default') |
|
33
|
|
|
{ |
|
34
|
9 |
|
$this->database = $database; |
|
35
|
9 |
|
$this->connection = $connection; |
|
36
|
9 |
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Gets the specified driver from the specified database connection. |
|
40
|
|
|
* |
|
41
|
|
|
* @param array $database |
|
42
|
|
|
* @param string $connection |
|
43
|
|
|
* @return \Rougin\Describe\Driver\DriverInterface|null |
|
44
|
|
|
*/ |
|
45
|
9 |
|
public function getDriver(array $database, $connection) |
|
46
|
3 |
|
{ |
|
47
|
9 |
|
$driver = null; |
|
48
|
|
|
|
|
49
|
9 |
|
switch ($database[$connection]['dbdriver']) { |
|
50
|
9 |
|
case 'mysql': |
|
51
|
9 |
|
case 'mysqli': |
|
52
|
|
|
$database = $database[$connection]['database']; |
|
53
|
|
|
|
|
54
|
|
|
$pdo = new PDO( |
|
55
|
|
|
'mysql:host=' . $database[$connection]['hostname'] . |
|
56
|
|
|
';dbname=' . $database[$connection]['database'], |
|
57
|
|
|
$database[$connection]['username'], |
|
58
|
|
|
$database[$connection]['password'] |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$driver = new MySQLDriver($pdo, $database); |
|
62
|
|
|
|
|
63
|
|
|
break; |
|
64
|
9 |
|
case 'pdo': |
|
65
|
9 |
|
case 'sqlite': |
|
66
|
9 |
|
case 'sqlite3': |
|
67
|
9 |
|
$pdo = new PDO($database[$connection]['hostname']); |
|
68
|
|
|
|
|
69
|
9 |
|
$driver = new SQLiteDriver($pdo); |
|
70
|
|
|
|
|
71
|
9 |
|
break; |
|
72
|
9 |
|
} |
|
73
|
|
|
|
|
74
|
9 |
|
return $driver; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns the result. |
|
79
|
|
|
* |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
6 |
|
public function getTable($table) |
|
83
|
|
|
{ |
|
84
|
6 |
|
$driver = $this->getDriver($this->database, $this->connection); |
|
85
|
|
|
|
|
86
|
6 |
|
return $driver->getTable($table); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Shows the list of tables. |
|
91
|
|
|
* |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
3 |
|
public function showTables() |
|
95
|
|
|
{ |
|
96
|
3 |
|
$driver = $this->getDriver($this->database, $this->connection); |
|
97
|
|
|
|
|
98
|
3 |
|
return $driver->showTables(); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|