1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Phive Queue package. |
5
|
|
|
* |
6
|
|
|
* (c) Eugene Leonovich <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Phive\Queue\Pdo; |
13
|
|
|
|
14
|
|
|
use Phive\Queue\NoItemAvailableException; |
15
|
|
|
|
16
|
|
|
class GenericPdoQueue extends PdoQueue |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected static $popSqls = [ |
22
|
|
|
'pgsql' => 'SELECT item FROM %s(%d)', |
23
|
|
|
'firebird' => 'SELECT item FROM %s(%d)', |
24
|
|
|
'informix' => 'EXECUTE PROCEDURE %s(%d)', |
25
|
|
|
'mysql' => 'CALL %s(%d)', |
26
|
|
|
'cubrid' => 'CALL %s(%d)', |
27
|
|
|
'ibm' => 'CALL %s(%d)', |
28
|
|
|
'oci' => 'CALL %s(%d)', |
29
|
|
|
'odbc' => 'CALL %s(%d)', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $routineName; |
36
|
|
|
|
37
|
40 |
|
public function __construct(\PDO $pdo, $tableName, $routineName = null) |
38
|
|
|
{ |
39
|
40 |
|
parent::__construct($pdo, $tableName); |
40
|
|
|
|
41
|
40 |
|
$this->routineName = $routineName ?: $this->tableName.'_pop'; |
42
|
40 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
24 |
|
public function pop() |
48
|
|
|
{ |
49
|
24 |
|
$stmt = $this->pdo->query($this->getPopSql()); |
50
|
22 |
|
$result = $stmt->fetchColumn(); |
51
|
22 |
|
$stmt->closeCursor(); |
52
|
|
|
|
53
|
22 |
|
if (false === $result) { |
54
|
4 |
|
throw new NoItemAvailableException($this); |
55
|
|
|
} |
56
|
|
|
|
57
|
22 |
|
return $result; |
58
|
|
|
} |
59
|
|
|
|
60
|
40 |
|
protected function supportsDriver($driverName) |
61
|
|
|
{ |
62
|
40 |
|
return isset(static::$popSqls[$driverName]); |
63
|
|
|
} |
64
|
|
|
|
65
|
24 |
|
protected function getPopSql() |
66
|
|
|
{ |
67
|
24 |
|
return sprintf( |
68
|
24 |
|
static::$popSqls[$this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)], |
69
|
24 |
|
$this->routineName, |
70
|
24 |
|
time() |
71
|
24 |
|
); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|