33namespace Laminas \Db \Mysql ;
44
55use InvalidArgumentException ;
6+ use Laminas \Db \Adapter \AbstractAdapter ;
67use Laminas \Db \Adapter \AdapterInterface ;
8+ use Laminas \Db \Adapter \ParameterContainer ;
9+ use Laminas \Db \Platform ;
710use Laminas \Db \Adapter \Profiler ;
11+ use Laminas \Db \Driver \DriverInterface ;
12+ use Laminas \Db \Driver \Pdo \Pdo ;
13+ use Laminas \Db \Driver \ResultInterface ;
14+ use Laminas \Db \Exception ;
815use Laminas \Db \ResultSet ;
916
1017use function func_get_args ;
1623use function strtolower ;
1724
1825/**
19- * @property Driver\ DriverInterface $driver
26+ * @property DriverInterface $driver
2027 * @property Platform\PlatformInterface $platform
2128 */
22- class Adapter implements AdapterInterface, Profiler \ProfilerAwareInterface
29+ class Adapter extends AbstractAdapter
2330{
2431 /**
2532 * Query Mode Constants
@@ -39,7 +46,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface
3946
4047 public const VALUE_QUOTE_SEPARATOR = 'quoteSeparator ' ;
4148
42- /** @var Driver\ DriverInterface */
49+ /** @var DriverInterface */
4350 protected $ driver ;
4451
4552 /** @var Platform\PlatformInterface */
@@ -58,7 +65,7 @@ class Adapter implements AdapterInterface, Profiler\ProfilerAwareInterface
5865 */
5966 protected $ lastPreparedStatement ;
6067 /**
61- * @param Driver\ DriverInterface|array $driver
68+ * @param DriverInterface|array $driver
6269 * @throws Exception\InvalidArgumentException
6370 */
6471 public function __construct (
@@ -76,9 +83,9 @@ public function __construct(
7683 $ profiler = $ this ->createProfiler ($ parameters );
7784 }
7885 $ driver = $ this ->createDriver ($ parameters );
79- } elseif (! $ driver instanceof Driver \ DriverInterface) {
86+ } elseif (! $ driver instanceof DriverInterface) {
8087 throw new Exception \InvalidArgumentException (
81- 'The supplied or instantiated driver object does not implement ' . Driver \ DriverInterface::class
88+ 'The supplied or instantiated driver object does not implement ' . DriverInterface::class
8289 );
8390 }
8491
@@ -121,7 +128,7 @@ public function getProfiler()
121128 * getDriver()
122129 *
123130 * @throws Exception\RuntimeException
124- * @return Driver\ DriverInterface
131+ * @return DriverInterface
125132 */
126133 public function getDriver ()
127134 {
@@ -198,7 +205,7 @@ public function query(
198205 $ result = $ this ->driver ->getConnection ()->execute ($ sql );
199206 }
200207
201- if ($ result instanceof Driver \ ResultInterface && $ result ->isQueryResult ()) {
208+ if ($ result instanceof ResultInterface && $ result ->isQueryResult ()) {
202209 $ resultSet = $ resultPrototype ?? $ this ->queryResultSetPrototype ;
203210 $ resultSetCopy = clone $ resultSet ;
204211
@@ -254,23 +261,23 @@ public function getHelpers()
254261 /**
255262 * @param string $name
256263 * @throws Exception\InvalidArgumentException
257- * @return Driver\ DriverInterface|Platform\PlatformInterface
264+ * @return DriverInterface|Platform\PlatformInterface
258265 */
259- public function __get ($ name )
260- {
261- switch (strtolower ($ name )) {
262- case 'driver ' :
263- return $ this ->driver ;
264- case 'platform ' :
265- return $ this ->platform ;
266- default :
267- throw new Exception \InvalidArgumentException ('Invalid magic property on adapter ' );
268- }
269- }
266+ // public function __get($name)
267+ // {
268+ // switch (strtolower($name)) {
269+ // case 'driver':
270+ // return $this->driver;
271+ // case 'platform':
272+ // return $this->platform;
273+ // default:
274+ // throw new Exception\InvalidArgumentException('Invalid magic property on adapter');
275+ // }
276+ // }
270277
271278 /**
272279 * @param array $parameters
273- * @return Driver\ DriverInterface
280+ * @return DriverInterface
274281 * @throws InvalidArgumentException
275282 * @throws Exception\InvalidArgumentException
276283 */
@@ -282,7 +289,7 @@ protected function createDriver($parameters)
282289 );
283290 }
284291
285- if ($ parameters ['driver ' ] instanceof Driver \ DriverInterface) {
292+ if ($ parameters ['driver ' ] instanceof DriverInterface) {
286293 return $ parameters ['driver ' ];
287294 }
288295
@@ -301,44 +308,33 @@ protected function createDriver($parameters)
301308 $ driverName = strtolower ($ parameters ['driver ' ]);
302309 switch ($ driverName ) {
303310 case 'mysqli ' :
304- $ driver = new Driver \Mysqli \Mysqli ($ parameters , null , null , $ options );
305- break ;
306- case 'sqlsrv ' :
307- $ driver = new Driver \Sqlsrv \Sqlsrv ($ parameters );
308- break ;
309- case 'oci8 ' :
310- $ driver = new Driver \Oci8 \Oci8 ($ parameters );
311- break ;
312- case 'pgsql ' :
313- $ driver = new Driver \Pgsql \Pgsql ($ parameters );
314- break ;
315- case 'ibmdb2 ' :
316- $ driver = new Driver \IbmDb2 \IbmDb2 ($ parameters );
311+ $ driver = new Driver \Mysqli \Driver ($ parameters , null , null , $ options );
317312 break ;
318313 case 'pdo ' :
319314 default :
320315 if ($ driverName === 'pdo ' || strpos ($ driverName , 'pdo ' ) === 0 ) {
321- $ driver = new Driver \ Pdo \ Pdo ($ parameters );
316+ $ driver = new Pdo ($ parameters );
322317 }
323318 }
324319
325- if (! isset ($ driver ) || ! $ driver instanceof Driver \ DriverInterface) {
320+ if (! isset ($ driver ) || ! $ driver instanceof DriverInterface) {
326321 throw new Exception \InvalidArgumentException ('DriverInterface expected ' );
327322 }
328323
329324 return $ driver ;
330325 }
331326
332327 /**
328+ * todo: replace with factory
333329 * @param array $parameters
334330 * @return Platform\PlatformInterface
335331 */
336332 protected function createPlatform (array $ parameters )
337333 {
338334 if (isset ($ parameters ['platform ' ])) {
339335 $ platformName = $ parameters ['platform ' ];
340- } elseif ($ this ->driver instanceof Driver \ DriverInterface) {
341- $ platformName = $ this ->driver ->getDatabasePlatformName (Driver \ DriverInterface::NAME_FORMAT_CAMELCASE );
336+ } elseif ($ this ->driver instanceof DriverInterface) {
337+ $ platformName = $ this ->driver ->getDatabasePlatformName (DriverInterface::NAME_FORMAT_CAMELCASE );
342338 } else {
343339 throw new Exception \InvalidArgumentException (
344340 'A platform could not be determined from the provided configuration '
@@ -348,87 +344,40 @@ protected function createPlatform(array $parameters)
348344 // currently only supported by the IbmDb2 & Oracle concrete implementations
349345 $ options = $ parameters ['platform_options ' ] ?? [];
350346
347+
348+ // todo: replace with factory
351349 switch ($ platformName ) {
352350 case 'Mysql ' :
353351 // mysqli or pdo_mysql driver
354- if ($ this ->driver instanceof Driver \Mysqli \Mysqli || $ this ->driver instanceof Driver \ Pdo \ Pdo) {
352+ if ($ this ->driver instanceof Driver \Mysqli \Driver || $ this ->driver instanceof Pdo) {
355353 $ driver = $ this ->driver ;
356354 } else {
357355 $ driver = null ;
358356 }
359357 return new Platform \Mysql ($ driver );
360- case 'SqlServer ' :
361- // PDO is only supported driver for quoting values in this platform
362- return new Platform \SqlServer ($ this ->driver instanceof Driver \Pdo \Pdo ? $ this ->driver : null );
363- case 'Oracle ' :
364- if ($ this ->driver instanceof Driver \Oci8 \Oci8 || $ this ->driver instanceof Driver \Pdo \Pdo) {
365- $ driver = $ this ->driver ;
366- } else {
367- $ driver = null ;
368- }
369- return new Platform \Oracle ($ options , $ driver );
370- case 'Sqlite ' :
371- // PDO is only supported driver for quoting values in this platform
372- if ($ this ->driver instanceof Driver \Pdo \Pdo) {
373- return new Platform \Sqlite ($ this ->driver );
374- }
375- return new Platform \Sqlite (null );
376- case 'Postgresql ' :
377- // pgsql or pdo postgres driver
378- if ($ this ->driver instanceof Driver \Pgsql \Pgsql || $ this ->driver instanceof Driver \Pdo \Pdo) {
379- $ driver = $ this ->driver ;
380- } else {
381- $ driver = null ;
382- }
383- return new Platform \Postgresql ($ driver );
384- case 'IbmDb2 ' :
385- // ibm_db2 driver escaping does not need an action connection
386- return new Platform \IbmDb2 ($ options );
387358 default :
388359 return new Platform \Sql92 ();
389360 }
390361 }
391362
392363 /**
364+ * todo: remains in abstract adapter
393365 * @param array $parameters
394366 * @return Profiler\ProfilerInterface
395367 * @throws Exception\InvalidArgumentException
396368 */
397- protected function createProfiler ($ parameters )
398- {
399- if ($ parameters ['profiler ' ] instanceof Profiler \ProfilerInterface) {
400- return $ parameters ['profiler ' ];
401- }
402-
403- if (is_bool ($ parameters ['profiler ' ])) {
404- return $ parameters ['profiler ' ] === true ? new Profiler \Profiler () : null ;
405- }
406-
407- throw new Exception \InvalidArgumentException (
408- '"profiler" parameter must be an instance of ProfilerInterface or a boolean '
409- );
410- }
411-
412- /**
413- * @deprecated
414- *
415- * @param array $parameters
416- * @return Driver\DriverInterface
417- * @throws InvalidArgumentException
418- * @throws Exception\InvalidArgumentException
419- */
420- protected function createDriverFromParameters (array $ parameters )
421- {
422- return $ this ->createDriver ($ parameters );
423- }
424-
425- /**
426- * @deprecated
427- *
428- * @return Platform\PlatformInterface
429- */
430- protected function createPlatformFromDriver (Driver \DriverInterface $ driver )
431- {
432- return $ this ->createPlatform ($ driver );
433- }
369+ // protected function createProfiler($parameters)
370+ // {
371+ // if ($parameters['profiler'] instanceof Profiler\ProfilerInterface) {
372+ // return $parameters['profiler'];
373+ // }
374+
375+ // if (is_bool($parameters['profiler'])) {
376+ // return $parameters['profiler'] === true ? new Profiler\Profiler() : null;
377+ // }
378+
379+ // throw new Exception\InvalidArgumentException(
380+ // '"profiler" parameter must be an instance of ProfilerInterface or a boolean'
381+ // );
382+ // }
434383}
0 commit comments