Skip to content

Commit

Permalink
Enhance supported driver check for pdo queues
Browse files Browse the repository at this point in the history
  • Loading branch information
rybakit committed Sep 8, 2014
1 parent 7b7059e commit b73aa0f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Pdo/GenericPdoQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function pop()
return $result;
}

public function getSupportedDrivers()
protected function supportsDriver($driverName)
{
return array_keys(static::$popSqls);
return isset(static::$popSqls[$driverName]);
}

protected function getPopSql()
Expand Down
13 changes: 7 additions & 6 deletions src/Pdo/PdoQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ abstract class PdoQueue implements Queue

public function __construct(\PDO $pdo, $tableName)
{
$supportedDrivers = (array) $this->getSupportedDrivers();
$driver = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
$driverName = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);

if (!in_array($driver, $supportedDrivers, true)) {
throw new \InvalidArgumentException(sprintf('PDO driver "%s" is unsupported by "%s".', $driver, get_class($this)));
if (!$this->supportsDriver($driverName)) {
throw new \InvalidArgumentException(sprintf('PDO driver "%s" is unsupported by "%s".', $driverName, get_class($this)));
}

$this->pdo = $pdo;
Expand Down Expand Up @@ -65,7 +64,9 @@ public function clear()
}

/**
* @return array
* @param string $driverName
*
* @return bool
*/
abstract public function getSupportedDrivers();
abstract protected function supportsDriver($driverName);
}
4 changes: 2 additions & 2 deletions src/Pdo/SqlitePdoQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function pop()
throw new NoItemAvailableException($this);
}

public function getSupportedDrivers()
protected function supportsDriver($driverName)
{
return ['sqlite'];
return 'sqlite' === $driverName;
}
}

0 comments on commit b73aa0f

Please sign in to comment.