1 | <?php |
||
55 | class Connection extends Dispatcher |
||
56 | { |
||
57 | /** |
||
58 | * State when initialized |
||
59 | */ |
||
60 | const STATE_INITIALIZED = 0; |
||
61 | |||
62 | /** |
||
63 | * State when connected to SGDB |
||
64 | */ |
||
65 | const STATE_CONNECTED = 1; |
||
66 | |||
67 | /** |
||
68 | * State when disconnected from SGDB |
||
69 | */ |
||
70 | const STATE_DISCONNECTED = 2; |
||
71 | |||
72 | /** |
||
73 | * State when an exception has been thrown |
||
74 | */ |
||
75 | const STATE_ERROR = 3; |
||
76 | |||
77 | /** |
||
78 | * Connection options |
||
79 | * |
||
80 | * @var array |
||
81 | */ |
||
82 | protected $options = array(); |
||
83 | |||
84 | /** |
||
85 | * DBAL Connection object |
||
86 | * |
||
87 | * @var DbalConnection |
||
88 | */ |
||
89 | protected $driver; |
||
90 | |||
91 | /** |
||
92 | * Schema object |
||
93 | * |
||
94 | * @var \Doctrine\DBAL\Schema\Schema |
||
95 | */ |
||
96 | protected $schema; |
||
97 | |||
98 | /** |
||
99 | * Current state of the connection |
||
100 | * |
||
101 | * @var integer |
||
102 | */ |
||
103 | protected $state = self::STATE_INITIALIZED; |
||
104 | |||
105 | /** |
||
106 | * Tables objects (cache) |
||
107 | * |
||
108 | * @var array |
||
109 | */ |
||
110 | protected $tables; |
||
111 | |||
112 | /** |
||
113 | * Constructor with generic configuration parameters (array) |
||
114 | * Options are used by Doctrine\DBAL\Connection, please refer to |
||
115 | * documentation: |
||
116 | * |
||
117 | * http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest |
||
118 | * |
||
119 | * other options: |
||
120 | * - autoConnect: (boolean) should connect on init (defaults to false) |
||
121 | * |
||
122 | * @param array $options Configuration options |
||
123 | * |
||
124 | * @return void |
||
|
|||
125 | */ |
||
126 | public function __construct(array $options = array()) |
||
134 | |||
135 | /** |
||
136 | * Establish connection to database |
||
137 | * |
||
138 | * @throws Exceptions\ConnectionErrorException when failing to connect |
||
139 | * @return boolean |
||
140 | */ |
||
141 | public function connect() |
||
160 | |||
161 | /** |
||
162 | * End connection to database |
||
163 | * |
||
164 | * @throws Exceptions\ConnectionErrorException when failing to disconnect (?) |
||
165 | * @return boolean |
||
166 | */ |
||
167 | public function disconnect() |
||
181 | |||
182 | /** |
||
183 | * Sets an option value |
||
184 | * |
||
185 | * @param string $option Option's key |
||
186 | * @param mixed $value Option value |
||
187 | * |
||
188 | * @return Connection |
||
189 | */ |
||
190 | public function set($option, $value) |
||
196 | |||
197 | /** |
||
198 | * Returns an option value or $default if option is not defined. |
||
199 | * |
||
200 | * @param string $option Option key |
||
201 | * @param mixed $default Option value |
||
202 | * |
||
203 | * @return mixed |
||
204 | */ |
||
205 | public function get($option, $default = null) |
||
211 | |||
212 | /** |
||
213 | * Returns all options |
||
214 | * |
||
215 | * @return array |
||
216 | */ |
||
217 | public function getOptions() |
||
221 | |||
222 | /** |
||
223 | * Sets (merge) multiple options values |
||
224 | * |
||
225 | * @param array $options List of options (keys->values) |
||
226 | * |
||
227 | * @return Connection |
||
228 | */ |
||
229 | public function setOptions(array $options = array()) |
||
235 | |||
236 | /** |
||
237 | * Returns the DBAL instance for this connection |
||
238 | * |
||
239 | * @return DbalConnection |
||
240 | */ |
||
241 | public function getDriver() |
||
249 | |||
250 | /** |
||
251 | * Defines a driver |
||
252 | * |
||
253 | * @param DbalConnection $driver The DBAL Connection object |
||
254 | * |
||
255 | * @return Connection |
||
256 | */ |
||
257 | public function setDriver(DbalConnection $driver) |
||
263 | |||
264 | /** |
||
265 | * Returns current database schema |
||
266 | * |
||
267 | * @return \Doctrine\DBAL\Schema\Schema |
||
268 | */ |
||
269 | public function getSchema() |
||
280 | |||
281 | /** |
||
282 | * Tells if the connection is established |
||
283 | * |
||
284 | * @return boolean |
||
285 | */ |
||
286 | public function isConnected() |
||
291 | |||
292 | /** |
||
293 | * Tells if the connection is in error state |
||
294 | * |
||
295 | * @return boolean |
||
296 | */ |
||
297 | public function isError() |
||
302 | |||
303 | /** |
||
304 | * Executes a query and return results |
||
305 | * |
||
306 | * @param Query $query The Query object |
||
307 | * @param array $params Query values (if any) |
||
308 | * @param array $options Extras query options |
||
309 | * |
||
310 | * @return mixed |
||
311 | */ |
||
312 | public function execute(Query $query, array $params = array(), |
||
356 | |||
357 | /** |
||
358 | * Returns a new instance of a QueryBridge |
||
359 | * |
||
360 | * @return QueryBridge |
||
361 | */ |
||
362 | public function newQueryBrige() |
||
366 | |||
367 | /** |
||
368 | * Defines current state and trigger a STATE_CHANGE event |
||
369 | * |
||
370 | * @param integer $state New connection's state |
||
371 | * |
||
372 | * @return Connection |
||
373 | */ |
||
374 | public function setState($state) |
||
386 | |||
387 | /** |
||
388 | * Returns current connection state |
||
389 | * |
||
390 | * @return integer |
||
391 | */ |
||
392 | public function getState() |
||
396 | |||
397 | /** |
||
398 | * Sets an error Exception and toggle error state |
||
399 | * |
||
400 | * @param \Exception $exception The exception to be thrown |
||
401 | * |
||
402 | * @return \Exception |
||
403 | */ |
||
404 | public function setErrorException(\Exception $exception) |
||
411 | |||
412 | /** |
||
413 | * Returns a table object representing a database table |
||
414 | * |
||
415 | * @param string $tableName Table name |
||
416 | * |
||
417 | * @throws Exceptions\TableNotFoundException if table is not found |
||
418 | * @return Table |
||
419 | */ |
||
420 | public function table($tableName) |
||
443 | |||
444 | /** |
||
445 | * Returns the last inserted ID in the database (if driver supports it) |
||
446 | * |
||
447 | * @return integer |
||
448 | */ |
||
449 | public function lastInsertId() |
||
454 | |||
455 | /** |
||
456 | * Starts a new transaction |
||
457 | * |
||
458 | * @return Connection |
||
459 | */ |
||
460 | public function beginTransaction() |
||
466 | |||
467 | /** |
||
468 | * Commits the current transaction |
||
469 | * |
||
470 | * @return Connection |
||
471 | */ |
||
472 | public function commit() |
||
478 | |||
479 | /** |
||
480 | * Cancels the current transaction |
||
481 | * |
||
482 | * @return Connection |
||
483 | */ |
||
484 | public function rollBack() |
||
490 | } |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.