1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 Underground Elephant |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
* |
18
|
|
|
* @package qpush-bundle |
19
|
|
|
* @copyright Underground Elephant 2014 |
20
|
|
|
* @license Apache License, Version 2.0 |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Uecode\Bundle\QPushBundle\Provider; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @author Keith Kirk <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class ProviderRegistry |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* All services tagged with `uecode_qpush.receive` |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private $queues; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor. |
38
|
|
|
*/ |
39
|
1 |
|
public function __construct() |
40
|
|
|
{ |
41
|
1 |
|
$this->queues = []; |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Adds a Listener to the chain based on priority |
46
|
|
|
* |
47
|
|
|
* @param string $name The name of the Queue |
48
|
|
|
* @param ProviderInterface $service The QueueProvider |
49
|
|
|
*/ |
50
|
1 |
|
public function addProvider($name, ProviderInterface $service) |
51
|
|
|
{ |
52
|
1 |
|
$this->queues[$name] = $service; |
53
|
1 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns the Queues |
57
|
|
|
* |
58
|
|
|
* @return array |
59
|
|
|
*/ |
60
|
1 |
|
public function all() |
61
|
|
|
{ |
62
|
1 |
|
return $this->queues; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Checks whether a Queue Provider exists in the Regisitry |
67
|
|
|
* |
68
|
|
|
* @param string $name The name of the Queue to check for |
69
|
|
|
* |
70
|
|
|
* @return Boolean |
71
|
|
|
*/ |
72
|
1 |
|
public function has($name) |
73
|
|
|
{ |
74
|
1 |
|
return array_key_exists($name, $this->queues); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Returns a Single QueueProvider by Queue Name |
79
|
|
|
* |
80
|
|
|
* @param string $name |
81
|
|
|
* |
82
|
|
|
* @throws \InvalidArgumentException |
83
|
|
|
* |
84
|
|
|
* @return ProviderInterface |
85
|
|
|
*/ |
86
|
1 |
|
public function get($name) |
87
|
|
|
{ |
88
|
1 |
|
if (!array_key_exists($name, $this->queues)) { |
89
|
1 |
|
throw new \InvalidArgumentException("The queue does not exist. {$name}"); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
return $this->queues[$name]; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|