1 | <?php |
||
17 | class DoctrineProvider extends AbstractProvider |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $queues = array(); |
||
23 | |||
24 | /** |
||
25 | * @var EntityManager |
||
26 | */ |
||
27 | protected $dispatcher; |
||
28 | |||
29 | /** |
||
30 | * @var EventDispatcherInterface |
||
31 | */ |
||
32 | protected $eventDispatcher; |
||
33 | |||
34 | /** |
||
35 | * @var EntityRepository |
||
36 | */ |
||
37 | protected $repisotory; |
||
38 | |||
39 | /** |
||
40 | * @var FactoryInterface |
||
41 | */ |
||
42 | protected $factory; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $dataClass; |
||
48 | |||
49 | /** |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $queueBuffers = []; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $queueOptions = array(); |
||
58 | |||
59 | /** |
||
60 | * @var bool |
||
61 | */ |
||
62 | protected $postponeOnCli = true; |
||
63 | |||
64 | public function __construct($name, array $options, $client, Cache $cache, Logger $logger) |
||
65 | { |
||
66 | $options = array_merge(array( |
||
67 | 'messages_to_receive' => 1, |
||
68 | 'fifo_receive' => true, |
||
69 | 'logging_enabled' => true, |
||
70 | ), $options); |
||
71 | |||
72 | $this->name = $name; |
||
73 | $this->options = $options; |
||
74 | $this->dispatcher = $client; |
||
75 | $this->cache = $cache; |
||
76 | $this->logger = $logger; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @param string $dataClass |
||
81 | */ |
||
82 | public function setRepositoryForClass($dataClass) |
||
83 | { |
||
84 | $this->dataClass = $dataClass; |
||
85 | $this->repisotory = $this->dispatcher->getRepository($this->dataClass); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @param FactoryInterface $factory |
||
90 | */ |
||
91 | public function setFactory(FactoryInterface $factory) |
||
95 | |||
96 | /** |
||
97 | * @return QueueMessageInterface |
||
98 | */ |
||
99 | public function create() |
||
100 | { |
||
101 | $this->log(200, "Queue has been created."); |
||
102 | return $this->factory->createNew(); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param EventDispatcherInterface $eventDispatcher |
||
107 | */ |
||
108 | public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function getProvider() |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function publish(array $message, array $options = []) |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function receive(array $options = []) |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | public function delete($id) |
||
211 | |||
212 | /** |
||
213 | * {@inheritdoc} |
||
214 | */ |
||
215 | public function destroy() |
||
240 | |||
241 | /** |
||
242 | * Receive message. |
||
243 | */ |
||
244 | public function onKernelTerminate() |
||
250 | |||
251 | /** |
||
252 | * Check whether this Backend is run on the CLI. |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | protected function isCommandLineInterface() |
||
260 | } |
||
261 |