1 | <?php |
||
17 | abstract class Driver { |
||
18 | |||
19 | /** |
||
20 | * The internal PDO connection that is wrapped by this driver. |
||
21 | * @var \PDO |
||
22 | */ |
||
23 | private $pdo; |
||
24 | |||
25 | /** |
||
26 | * The default schema used in the connection. |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $defaultSchema; |
||
30 | |||
31 | /** |
||
32 | * The connection parameters with which this connection was established. |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $config; |
||
36 | |||
37 | /** |
||
38 | * An instance of the descriptor used internally. |
||
39 | * @var \ntentan\atiaa\Descriptor |
||
40 | */ |
||
41 | private $descriptor; |
||
42 | private static $transactionCount = 0; |
||
43 | |||
44 | /** |
||
45 | * Creates a new instance of the Atiaa driver. This class is usually initiated |
||
46 | * through the \ntentan\atiaa\Atiaa::getConnection() method. For example |
||
47 | * to create a new instance of a connection to a mysql database. |
||
48 | * |
||
49 | * ````php |
||
50 | * use ntentan\atiaa\Driver; |
||
51 | * |
||
52 | * \\ This automatically insitatiates the driver class |
||
53 | * $driver = Driver::getConnection( |
||
54 | * array( |
||
55 | * 'driver' => 'mysql', |
||
56 | * 'user' => 'root', |
||
57 | * 'password' => 'rootpassy', |
||
58 | * 'host' => 'localhost', |
||
59 | * 'dbname' => 'somedb' |
||
60 | * ) |
||
61 | * ); |
||
62 | * |
||
63 | * var_dump($driver->query("SELECT * FROM some_table"); |
||
64 | * var_dump($driver->describe()); |
||
65 | * ```` |
||
66 | * |
||
67 | * @param array<string> $config The configuration with which to connect to the database. |
||
68 | */ |
||
69 | 33 | public function __construct($config = null) { |
|
85 | |||
86 | 20 | public function __destruct() { |
|
89 | |||
90 | /** |
||
91 | * Close a connection to the database server. |
||
92 | */ |
||
93 | 20 | public function disconnect() { |
|
97 | |||
98 | /** |
||
99 | * Get the default schema of the current connection. |
||
100 | * @return string |
||
101 | */ |
||
102 | 11 | public function getDefaultSchema() { |
|
105 | |||
106 | /** |
||
107 | * Use the PDO driver to quote a string. |
||
108 | * @param type $string |
||
109 | * @return string |
||
110 | */ |
||
111 | 3 | public function quote($string) { |
|
114 | |||
115 | /** |
||
116 | * |
||
117 | * @param boolean $status |
||
|
|||
118 | * @param \PDOStatement $result |
||
119 | */ |
||
120 | 25 | private function fetchRows($statement) { |
|
128 | |||
129 | /** |
||
130 | * Pepare and execute a query, while binding data at the same time. Prevents |
||
131 | * the writing of repetitive prepare and execute statements. This method |
||
132 | * returns an array which contains the results of the query that was |
||
133 | * executed. For queries which do not return any results a null is returned. |
||
134 | * |
||
135 | * @todo Add a parameter to cache prepared statements so they can be reused easily. |
||
136 | * |
||
137 | * @param string $query The query to be executed quoted in PDO style |
||
138 | * @param false|array<mixed> $bindData The data to be bound to the query object. |
||
139 | * @return array<mixed> |
||
140 | */ |
||
141 | 29 | public function query($query, $bindData = false) { |
|
157 | |||
158 | /** |
||
159 | * Runs a query but ensures that all identifiers are properly quoted by calling |
||
160 | * the Driver::quoteQueryIdentifiers method on the query before executing it. |
||
161 | * |
||
162 | * @param string $query |
||
163 | * @param false|array<mixed> $bindData |
||
164 | * @return array<mixed> |
||
165 | */ |
||
166 | 16 | public function quotedQuery($query, $bindData = false) { |
|
169 | |||
170 | /** |
||
171 | * Expands the configuration array into a format that can easily be passed |
||
172 | * to PDO. |
||
173 | * |
||
174 | * @param array $params The query parameters |
||
175 | * @return string |
||
176 | */ |
||
177 | 33 | private function expand($params) { |
|
195 | |||
196 | /** |
||
197 | * This method provides a system independent way of quoting identifiers in |
||
198 | * queries. By default all identifiers can be quoted with double quotes ("). |
||
199 | * When a query quoted with double quotes is passed through this method the |
||
200 | * output generated has the double quotes replaced with the quoting character |
||
201 | * of the target database platform. |
||
202 | * |
||
203 | * @param string $query |
||
204 | * @return string |
||
205 | */ |
||
206 | 19 | public function quoteQueryIdentifiers($query) { |
|
213 | |||
214 | /** |
||
215 | * Returns an array description of the schema represented by the connection. |
||
216 | * The description returns contains information about `tables`, `columns`, `keys`, |
||
217 | * `constraints`, `views` and `indices`. |
||
218 | * |
||
219 | * @return array<mixed> |
||
220 | */ |
||
221 | 6 | public function describe() { |
|
224 | |||
225 | /** |
||
226 | * Returns the description of a database table as an associative array. |
||
227 | * |
||
228 | * @param string $table |
||
229 | * @return array<mixed> |
||
230 | */ |
||
231 | 7 | public function describeTable($table) { |
|
242 | |||
243 | /** |
||
244 | * A wrapper arround PDO's beginTransaction method which uses a static reference |
||
245 | * counter to implement nested transactions. |
||
246 | */ |
||
247 | 6 | public function beginTransaction() { |
|
252 | |||
253 | /** |
||
254 | * A wrapper around PDO's commit transaction method which uses a static reference |
||
255 | * counter to implement nested transactions. |
||
256 | */ |
||
257 | 3 | public function commit() { |
|
262 | |||
263 | /** |
||
264 | * A wrapper around PDO's rollback transaction methd which rolls back all |
||
265 | * activities performed since the first call to begin transaction. |
||
266 | * Unfortunately, transactions cannot be rolled back in a nested fashion. |
||
267 | */ |
||
268 | 3 | public function rollback() { |
|
272 | |||
273 | /** |
||
274 | * Return the underlying PDO object. |
||
275 | * @return \PDO |
||
276 | */ |
||
277 | 3 | public function getPDO() { |
|
280 | |||
281 | /** |
||
282 | * Returns an instance of a descriptor for a given driver. |
||
283 | * @return \atiaa\Descriptor |
||
284 | */ |
||
285 | 13 | private function getDescriptor() { |
|
292 | |||
293 | /** |
||
294 | * A wrapper around PDO's lastInsertId() method. |
||
295 | * @return mixed |
||
296 | */ |
||
297 | public function getLastInsertId() { |
||
300 | |||
301 | /** |
||
302 | * Specify the default schema to use in cases where a schema is not provided |
||
303 | * as part of the table reference. |
||
304 | * @param string $defaultSchema |
||
305 | */ |
||
306 | public function setDefaultSchema($defaultSchema) { |
||
309 | |||
310 | abstract protected function getDriverName(); |
||
311 | |||
312 | abstract public function quoteIdentifier($identifier); |
||
313 | |||
314 | /** |
||
315 | * Returns a new instance of a driver based on the connection parameters |
||
316 | * passed to the method. The connection parameters are passed through an |
||
317 | * associative array with the following keys. |
||
318 | * |
||
319 | * driver |
||
320 | * : The name of the driver to use for the database connection. Supported |
||
321 | * drivers are `mysql` and `postgresql`. This parameter is required for |
||
322 | * all connections. |
||
323 | * |
||
324 | * user |
||
325 | * : The username to use for the database connection on platforms that |
||
326 | * support it. |
||
327 | * |
||
328 | * password |
||
329 | * : The password associated to the user specified in the connection. |
||
330 | * |
||
331 | * host |
||
332 | * : The host name of the database server. |
||
333 | * |
||
334 | * dbname |
||
335 | * : The name of the default database to use after the connection to the |
||
336 | * database is established. |
||
337 | * |
||
338 | * @param array $config |
||
339 | * @return \ntentan\atiaa\Driver |
||
340 | */ |
||
341 | /* public static function getConnection($config) |
||
342 | { |
||
343 | if (is_string($config) && file_exists($config)) { |
||
344 | require $config; |
||
345 | } else if ($config['driver'] == '') { |
||
346 | throw new DatabaseDriverException("Please specify a name for your database driver."); |
||
347 | } |
||
348 | try { |
||
349 | $class = "\\ntentan\\atiaa\\drivers\\" . ucfirst($config['driver']) . "Driver"; |
||
350 | return new $class($config); |
||
351 | } catch (\PDOException $e) { |
||
352 | throw new DatabaseDriverException("PDO failed to connect: {$e->getMessage()}", $e); |
||
353 | } |
||
354 | } */ |
||
355 | |||
356 | 3 | public function setCleanDefaults($cleanDefaults) { |
|
359 | |||
360 | } |
||
361 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.