1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Equip\Queue; |
4
|
|
|
|
5
|
|
|
use Equip\Command\OptionsInterface; |
6
|
|
|
use Exception; |
7
|
|
|
use League\Event\EmitterInterface; |
8
|
|
|
use Psr\Log\LoggerInterface; |
9
|
|
|
|
10
|
|
|
class Event |
11
|
|
|
{ |
12
|
|
|
const MESSAGE_ACKNOWLEDGE = 'message.acknowledge'; |
13
|
|
|
const MESSAGE_FINISH = 'message.finish'; |
14
|
|
|
const MESSAGE_REJECT = 'message.reject'; |
15
|
|
|
const QUEUE_SHUTDOWN = 'queue.shutdown'; |
16
|
|
|
const QUEUE_DRAINED = 'queue.drained'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var EmitterInterface |
20
|
|
|
*/ |
21
|
|
|
private $emitter; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var LoggerInterface |
25
|
|
|
*/ |
26
|
|
|
protected $logger; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param EmitterInterface $emitter |
30
|
|
|
* @param LoggerInterface $logger |
31
|
|
|
*/ |
32
|
5 |
|
public function __construct(EmitterInterface $emitter, LoggerInterface $logger) |
33
|
|
|
{ |
34
|
5 |
|
$this->emitter = $emitter; |
35
|
5 |
|
$this->logger = $logger; |
36
|
5 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Emits message acknowledgement events |
40
|
|
|
* |
41
|
|
|
* @param object $command |
42
|
|
|
*/ |
43
|
1 |
|
public function acknowledge($command) |
44
|
|
|
{ |
45
|
1 |
|
$this->emitter->emit(static::MESSAGE_ACKNOWLEDGE, $command); |
|
|
|
|
46
|
1 |
|
$this->logger->info(sprintf('`%s` job started', get_class($command->command()))); |
47
|
1 |
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Emits message finished events |
51
|
|
|
* |
52
|
|
|
* @param object $command |
53
|
|
|
*/ |
54
|
1 |
|
public function finish($command) |
55
|
|
|
{ |
56
|
1 |
|
$this->emitter->emit(static::MESSAGE_FINISH, $command); |
|
|
|
|
57
|
1 |
|
$this->logger->info(sprintf('`%s` job finished', get_class($command->command()))); |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Emits message rejection events |
62
|
|
|
* |
63
|
|
|
* @param object $command |
64
|
|
|
* @param Exception $exception |
65
|
|
|
*/ |
66
|
1 |
|
public function reject($command, Exception $exception) |
67
|
|
|
{ |
68
|
1 |
|
$this->emitter->emit(static::MESSAGE_REJECT, $command, $exception); |
|
|
|
|
69
|
1 |
|
$this->logger->error($exception->getMessage()); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Handles notifications for shutting down |
74
|
|
|
*/ |
75
|
1 |
|
public function shutdown() |
76
|
|
|
{ |
77
|
1 |
|
$this->emitter->emit(static::QUEUE_SHUTDOWN); |
78
|
1 |
|
$this->logger->notice('Shutting down'); |
79
|
1 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Handles notifications for shutting down when drained |
83
|
|
|
*/ |
84
|
1 |
|
public function drained() |
85
|
|
|
{ |
86
|
1 |
|
$this->emitter->emit(static::QUEUE_DRAINED); |
87
|
1 |
|
$this->logger->notice('Drained - Shutting down'); |
88
|
1 |
|
} |
89
|
|
|
} |
90
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.