forked from armetiz/LeezyPheanstalkBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PheanstalkLocator.php
67 lines (55 loc) · 1.41 KB
/
PheanstalkLocator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Leezy\PheanstalkBundle;
use Pheanstalk_PheanstalkInterface;
class PheanstalkLocator
{
private $pheanstalks;
private $default;
public function __construct()
{
$this->pheanstalks = array();
}
/**
* @return array
*/
public function getPheanstalks()
{
return $this->pheanstalks;
}
/**
* @param string $name
*
* @return \Pheanstalk_PheanstalkInterface
*/
public function getPheanstalk($name = null)
{
$name = null !== $name ? $name : $this->default;
if (array_key_exists($name, $this->pheanstalks)) {
return $this->pheanstalks[$name];
}
return null;
}
/**
* @return array
*/
public function getDefaultPheanstalk()
{
return $this->getPheanstalk();
}
/**
* @param string $name
* @param \Pheanstalk_PheanstalkInterface $pheanstalk
* @param boolean $default
*/
public function addPheanstalk($name, Pheanstalk_PheanstalkInterface $pheanstalk, $default = false)
{
if (!is_bool($default)) {
throw new \InvalidArgumentException('Default parameter have to be a boolean');
}
$this->pheanstalks[$name] = $pheanstalk;
// Set the default connection name
if ($default) {
$this->default = $name;
}
}
}