1 | <?php |
||
2 | |||
3 | namespace Pyrowman\PheanstalkBundle; |
||
4 | |||
5 | use Pheanstalk\PheanstalkInterface; |
||
6 | |||
7 | class PheanstalkLocator |
||
8 | { |
||
9 | /** |
||
10 | * @var PheanstalkInterface[] |
||
11 | */ |
||
12 | private $pheanstalks; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $default; |
||
18 | |||
19 | /** |
||
20 | * Constructor. |
||
21 | */ |
||
22 | 5 | public function __construct() |
|
23 | { |
||
24 | 5 | $this->pheanstalks = []; |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * @return PheanstalkInterface[] |
||
29 | */ |
||
30 | 4 | public function getPheanstalks() |
|
31 | { |
||
32 | 4 | return $this->pheanstalks; |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * @param string $name |
||
37 | * |
||
38 | * @return PheanstalkInterface |
||
39 | */ |
||
40 | 4 | public function getPheanstalk($name = null) |
|
41 | { |
||
42 | 4 | $name = null !== $name ? $name : $this->default; |
|
43 | |||
44 | 4 | if (array_key_exists($name, $this->pheanstalks)) { |
|
45 | 3 | return $this->pheanstalks[$name]; |
|
46 | } |
||
47 | |||
48 | 1 | return; |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @return array |
||
53 | */ |
||
54 | 3 | public function getDefaultPheanstalk() |
|
55 | { |
||
56 | 3 | return $this->getPheanstalk(); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param string $name |
||
61 | * @param PheanstalkInterface $pheanstalk |
||
62 | * @param bool $default |
||
63 | */ |
||
64 | 4 | public function addPheanstalk($name, PheanstalkInterface $pheanstalk, bool $default = false) |
|
65 | { |
||
66 | 4 | $this->pheanstalks[$name] = $pheanstalk; |
|
67 | |||
68 | // Set the default connection name |
||
69 | 4 | if ($default) { |
|
70 | 3 | $this->default = $name; |
|
71 | } |
||
72 | } |
||
73 | } |
||
74 |