1 | <?php |
||
10 | class WorkerContext |
||
11 | { |
||
12 | use LoggerAwareTrait; |
||
13 | |||
14 | private |
||
15 | $queueName, |
||
16 | $description, |
||
17 | $consumer, |
||
18 | $workerLogger, |
||
19 | $worker; |
||
20 | |||
21 | 8 | public function __construct(\Closure $worker, Consumer $consumer, $queueName) |
|
30 | |||
31 | 5 | public function getWorker() |
|
32 | { |
||
33 | 5 | if($this->worker instanceof \Closure) |
|
34 | { |
||
35 | 5 | $closure = $this->worker; |
|
36 | 5 | $this->worker = $closure(); |
|
37 | 5 | $this->worker->setLogger($this->getLoggerForWorker()); |
|
38 | } |
||
39 | |||
40 | 5 | return $this->worker; |
|
41 | } |
||
42 | |||
43 | 5 | private function getLoggerForWorker() |
|
44 | { |
||
45 | 5 | if($this->workerLogger instanceof LoggerInterface) |
|
46 | { |
||
47 | 1 | return $this->workerLogger; |
|
48 | } |
||
49 | |||
50 | 4 | return $this->logger; |
|
51 | } |
||
52 | |||
53 | 1 | public function setLogger(LoggerInterface $logger) |
|
60 | |||
61 | 1 | public function setWorkerLogger(LoggerInterface $logger) |
|
67 | |||
68 | 5 | public function getLogger() |
|
72 | |||
73 | public function getConsumer() |
||
77 | |||
78 | 1 | public function setDescription($description) |
|
84 | |||
85 | 2 | public function getDescription() |
|
89 | |||
90 | 3 | public function getQueueName() |
|
94 | } |
||
95 |