forked from ruckus/ruckusing-migrations
/
Base.php
153 lines (138 loc) · 2.72 KB
/
Base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
* Ruckusing
*
* @category Ruckusing
* @package Ruckusing_Adapter
* @author Cody Caughlan <codycaughlan % gmail . com>
* @link https://github.com/ruckus/ruckusing-migrations
*/
define('SQL_UNKNOWN_QUERY_TYPE', 1);
define('SQL_SELECT', 2);
define('SQL_INSERT', 4);
define('SQL_UPDATE', 8);
define('SQL_DELETE', 16);
define('SQL_ALTER', 32);
define('SQL_DROP', 64);
define('SQL_CREATE', 128);
define('SQL_SHOW', 256);
define('SQL_RENAME', 512);
define('SQL_SET', 1024);
/**
* Ruckusing_Adapter_Base
*
* @category Ruckusing
* @package Ruckusing_Adapter
* @author Cody Caughlan <codycaughlan % gmail . com>
* @link https://github.com/ruckus/ruckusing-migrations
*/
class Ruckusing_Adapter_Base
{
/**
* dsn
*
* @var array
*/
private $_dsn;
/**
* db
*
*/
private $_db;
/**
* connection to db
*
* @var object|mysqli
*/
protected $_conn;
/**
* logger
*
* @var Ruckusing_Util_Logger
*/
public $logger;
/**
* Creates an instance of Ruckusing_Adapter_Base
*
* @param array $dsn The current dsn
*
* @return Ruckusing_Adapter_Base
*/
public function __construct($dsn)
{
$this->set_dsn($dsn);
}
/**
* Set a dsn
*
* @param object $dsn The current dsn
*/
public function set_dsn($dsn)
{
$this->_dsn = $dsn;
}
/**
* Get the current dsn
*
* @return array
*/
public function get_dsn()
{
return $this->_dsn;
}
/**
* Set a db
*
* @param array $db The current db
*/
public function set_db($db)
{
$this->_db = $db;
}
/**
* Get the current db
*
* @return array
*/
public function get_db()
{
return $this->_db;
}
/**
* Set a logger
*
* @param Ruckusing_Util_Logger $logger The current logger
* @throws Ruckusing_Exception
*/
public function set_logger($logger)
{
if (!($logger instanceof Ruckusing_Util_Logger)) {
throw new Ruckusing_Exception(
'Logger parameter must be instance of Ruckusing_Util_Logger',
Ruckusing_Exception::INVALID_ARGUMENT
);
}
$this->logger = $logger;
}
/**
* Get the current logger
*
* @param $logger
* @return Ruckusing_Util_Logger
*/
public function get_logger($logger)
{
return $this->logger;
}
/**
* Check table exists
*
* @param string $tbl the table name
*
* @return boolean
*/
public function has_table($tbl)
{
return $this->table_exists($tbl);
}
}