1 | <?php namespace Comodojo\Daemon; |
||
33 | abstract class Process { |
||
34 | |||
35 | use PidTrait; |
||
36 | use EventsTrait; |
||
37 | use LoggerTrait; |
||
38 | use SignalsTrait; |
||
39 | |||
40 | /** |
||
41 | * Build the process |
||
42 | * |
||
43 | * @param int $niceness |
||
44 | * @param LoggerInterface $logger; |
||
|
|||
45 | * @param EventsManager $events; |
||
46 | */ |
||
47 | 1 | public function __construct($niceness = null, LoggerInterface $logger = null, EventsManager $events = null){ |
|
48 | |||
49 | 1 | if ( !Checks::cli() ) { |
|
50 | throw new RuntimeException("Process can run only in cli SAPI"); |
||
51 | } |
||
52 | |||
53 | 1 | if ( !Checks::signals() ) { |
|
54 | throw new Exception("Missing pcntl signaling"); |
||
55 | } |
||
56 | |||
57 | 1 | $this->logger = is_null($logger) ? LogManager::create('daemon', false)->getLogger() : $logger; |
|
58 | 1 | $this->events = is_null($events) ? EventsManager::create($this->logger) : $events; |
|
59 | |||
60 | // get current PID |
||
61 | 1 | $this->pid = ProcessTools::getPid(); |
|
62 | |||
63 | 1 | if ( ProcessTools::setNiceness($niceness) === false ) { |
|
64 | $this->logger->warning("Unable to set process niceness to $niceness"); |
||
65 | } |
||
66 | |||
67 | // register signals |
||
68 | 1 | $this->signals = new PosixSignals(); |
|
69 | 1 | $this->signals->any()->call(array($this, 'signalToEvent')); |
|
70 | |||
71 | 1 | } |
|
72 | |||
73 | /** |
||
74 | * The generic signal handler. |
||
75 | * |
||
76 | * It transforms a signal into framework catchable event. |
||
77 | * |
||
78 | * @param int $signal |
||
79 | * @return self |
||
80 | */ |
||
81 | public function signalToEvent($signal) { |
||
82 | |||
83 | if ( $this->pid == ProcessTools::getPid() ) { |
||
84 | |||
85 | $signame = $this->signals->signame($signal); |
||
86 | |||
87 | $this->logger->debug("Received $signame ($signal) signal, firing associated event(s)"); |
||
88 | |||
89 | $this->events->emit( new PosixEvent($signal, $this) ); |
||
90 | $this->events->emit( new PosixEvent($signame, $this) ); |
||
91 | |||
92 | } |
||
93 | |||
94 | return $this; |
||
95 | |||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Stop current process execution. |
||
100 | * |
||
101 | * @param integer $return_code |
||
102 | */ |
||
103 | public function end($return_code) { |
||
108 | |||
109 | } |
||
110 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.