1 | <?php |
||
30 | class DoctrineProvider extends AbstractProvider |
||
31 | { |
||
32 | |||
33 | protected $em; |
||
34 | protected $repository; |
||
35 | |||
36 | /** |
||
37 | * Constructor for Provider classes |
||
38 | * |
||
39 | * @param string $name Name of the Queue the provider is for |
||
40 | * @param array $options An array of configuration options for the Queue |
||
41 | * @param mixed $client A Queue Client for the provider |
||
42 | * @param Cache $cache An instance of Doctrine\Common\Cache\Cache |
||
43 | * @param Logger $logger An instance of Symfony\Bridge\Mongolog\Logger |
||
44 | */ |
||
45 | public function __construct($name, array $options, $client, Cache $cache, Logger $logger) |
||
46 | { |
||
47 | $this->name = $name; |
||
48 | $this->options = $options; |
||
49 | $this->cache = $cache; |
||
50 | $this->logger = $logger; |
||
51 | $this->em = $client; |
||
52 | $this->repository = $this->em->getRepository('Uecode\Bundle\QPushBundle\Entity\DoctrineMessage'); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Returns the name of the Queue that this Provider is for |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getName() |
||
64 | |||
65 | /** |
||
66 | * Returns the Queue Provider name |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getProvider() |
||
74 | |||
75 | /** |
||
76 | * Returns the Provider's Configuration Options |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | public function getOptions() |
||
84 | |||
85 | /** |
||
86 | * Returns the Cache service |
||
87 | * |
||
88 | * @return Cache |
||
89 | */ |
||
90 | public function getCache() |
||
94 | |||
95 | /** |
||
96 | * Returns the Logger service |
||
97 | * |
||
98 | * @return Logger |
||
99 | */ |
||
100 | public function getLogger() |
||
101 | { |
||
102 | return $this->logger; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Get repository |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | public function getRepository() |
||
111 | { |
||
112 | if (!$this->repository) { |
||
113 | return; |
||
114 | } |
||
115 | return $this->repository; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Creates the Queue |
||
120 | * |
||
121 | * All Create methods are idempotent, if the resource exists, the current ARN |
||
122 | * will be returned |
||
123 | */ |
||
124 | public function create() |
||
128 | |||
129 | /** |
||
130 | * Publishes a message to the Queue |
||
131 | * |
||
132 | * This method should return a string MessageId or Response |
||
133 | * |
||
134 | * @param array $message The message to queue |
||
135 | * @param array $options An array of options that override the queue defaults |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | public function publish(array $message, array $options = []) |
||
156 | |||
157 | /** |
||
158 | * Polls the Queue for Messages |
||
159 | * |
||
160 | * Depending on the Provider, this method may keep the connection open for |
||
161 | * a configurable amount of time, to allow for long polling. In most cases, |
||
162 | * this method is not meant to be used to long poll indefinitely, but should |
||
163 | * return in reasonable amount of time |
||
164 | * |
||
165 | * @param array $options An array of options that override the queue defaults |
||
166 | * |
||
167 | * @return array |
||
168 | */ |
||
169 | public function receive(array $options = []) |
||
193 | |||
194 | /** |
||
195 | * Deletes the Queue Message |
||
196 | * |
||
197 | * @param mixed $id A message identifier or resource |
||
198 | */ |
||
199 | public function delete($id) |
||
205 | |||
206 | /** |
||
207 | * Destroys a Queue and clears any Queue related Cache |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | public function destroy() |
||
219 | |||
220 | /** |
||
221 | * Returns a specific message |
||
222 | * |
||
223 | * @param integer $id |
||
224 | * |
||
225 | * @return Message |
||
226 | */ |
||
227 | public function getById($id) |
||
231 | |||
232 | /* |
||
233 | * Returns a query of the message queue |
||
234 | * |
||
235 | * @param string $contains |
||
236 | * @param DateTime $from |
||
237 | * @param DateTime $to |
||
238 | * |
||
239 | * @return Query |
||
240 | */ |
||
241 | |||
242 | public function findBy($contains = null, $from = null, $to = null) |
||
267 | } |
||
268 |