1 | <?php |
||
11 | class TableManager |
||
12 | { |
||
13 | /** |
||
14 | * |
||
15 | * @param Adapter $adapter |
||
16 | */ |
||
17 | protected $adapter; |
||
18 | |||
19 | /** |
||
20 | * |
||
21 | * @var Source\AbstractSchemaSource |
||
22 | */ |
||
23 | protected $metadata; |
||
24 | |||
25 | |||
26 | /** |
||
27 | * Global table prefix |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $table_prefix; |
||
31 | |||
32 | /** |
||
33 | * |
||
34 | * @var \Zend\Db\Sql\Sql |
||
35 | */ |
||
36 | protected $sql; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * |
||
41 | * @var Transaction |
||
42 | */ |
||
43 | protected $transaction; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * |
||
48 | * @var \ArrayObject |
||
49 | */ |
||
50 | protected $localTableCache; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * |
||
55 | * @var Driver\DriverInterface |
||
56 | */ |
||
57 | protected $driver; |
||
58 | |||
59 | /** |
||
60 | * |
||
61 | * @param Driver\DriverInterface $driver |
||
62 | */ |
||
63 | 131 | public function __construct(Driver\DriverInterface $driver) |
|
64 | { |
||
65 | 131 | $this->localTableCache = new ArrayObject(); |
|
66 | 131 | $this->driver = $driver; |
|
67 | 131 | $this->setDbAdapter($driver->getDbAdapter()); |
|
68 | |||
69 | 131 | $this->sql = new Sql($this->adapter); |
|
70 | 131 | } |
|
71 | |||
72 | |||
73 | |||
74 | |||
75 | /** |
||
76 | * Return a synthetic table |
||
77 | * |
||
78 | * @param string $table_name table name |
||
79 | * |
||
80 | * @throws Exception\InvalidArgumentException if table name is not valid |
||
81 | * |
||
82 | * @return Table |
||
83 | */ |
||
84 | 128 | public function table($table_name) |
|
100 | |||
101 | /** |
||
102 | * Return a generic select |
||
103 | * |
||
104 | * @return Select |
||
105 | */ |
||
106 | 1 | public function select() |
|
107 | { |
||
108 | 1 | $select = new Select(); |
|
109 | 1 | $select->setDbAdapter($this->adapter); |
|
110 | 1 | return $select; |
|
111 | } |
||
112 | |||
113 | |||
114 | |||
115 | /** |
||
116 | * Return a transaction object |
||
117 | * |
||
118 | * @return Transaction |
||
119 | */ |
||
120 | 3 | public function transaction() |
|
121 | { |
||
122 | 3 | if ($this->transaction === null) { |
|
123 | 3 | $this->transaction = new Transaction($this->adapter); |
|
124 | 3 | } |
|
125 | 3 | return $this->transaction; |
|
126 | } |
||
127 | |||
128 | |||
129 | |||
130 | |||
131 | /** |
||
132 | * Return underlyng Zend\Db\Adapter\Adapter |
||
133 | * |
||
134 | * @return Adapter $adapter |
||
135 | */ |
||
136 | 131 | public function getDbAdapter() |
|
140 | |||
141 | |||
142 | |||
143 | |||
144 | /** |
||
145 | * Set global table prefix |
||
146 | * |
||
147 | * @param string $table_prefix |
||
148 | * @return TableManager |
||
149 | */ |
||
150 | 3 | public function setTablePrefix($table_prefix) |
|
151 | { |
||
152 | 3 | $this->table_prefix = $table_prefix; |
|
153 | 3 | return $this; |
|
154 | } |
||
155 | |||
156 | /** |
||
157 | * Return global table prefix |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | 128 | public function getTablePrefix() |
|
165 | |||
166 | |||
167 | |||
168 | |||
169 | /** |
||
170 | * Return prefixed table name |
||
171 | * |
||
172 | * @param string $table |
||
173 | * @return string |
||
174 | */ |
||
175 | 6 | public function getPrefixedTable($table) |
|
179 | |||
180 | |||
181 | |||
182 | |||
183 | /** |
||
184 | * Return a metadata reader |
||
185 | * |
||
186 | * @return Source\AbstractSchemaSource |
||
187 | */ |
||
188 | 128 | public function metadata() |
|
195 | |||
196 | /** |
||
197 | * Set the database adapter |
||
198 | * |
||
199 | * @param Adapter $adapter |
||
200 | * @return TableManager |
||
201 | */ |
||
202 | 131 | protected function setDbAdapter(Adapter $adapter) |
|
207 | |||
208 | /** |
||
209 | * Return default metadata reader associated to an adapter |
||
210 | * |
||
211 | * @throws Exception\UnsupportedFeatureException |
||
212 | */ |
||
213 | 128 | protected function loadDefaultMetadata() |
|
225 | |||
226 | /** |
||
227 | * |
||
228 | * @param Source\AbstractSchemaSource $metadata |
||
229 | * @return TableManager |
||
230 | */ |
||
231 | 1 | public function setMetadata(Source\AbstractSchemaSource $metadata) |
|
236 | } |
||
237 |