Improved quality of docblock comments
This commit is contained in:
@ -7,17 +7,34 @@ class Signal
|
||||
{
|
||||
private $signo;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param integer $signo
|
||||
*/
|
||||
public function __construct(int $signo)
|
||||
{
|
||||
$this->signo = $signo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a signal handler, overwriting any previous handler
|
||||
*
|
||||
* @param callable $handler
|
||||
* @return void
|
||||
*/
|
||||
public function setHandler(callable $handler):void
|
||||
{
|
||||
pcntl_signal($this->signo, $handler);
|
||||
}
|
||||
|
||||
public function dispatch($pid=null):bool
|
||||
/**
|
||||
* Dispatch the signal to the specified pid. Default is own pid
|
||||
*
|
||||
* @param int $pid
|
||||
* @return boolean
|
||||
*/
|
||||
public function dispatch(int $pid=null):bool
|
||||
{
|
||||
return posix_kill($pid?:posix_getpid(), $this->signo);
|
||||
}
|
||||
|
@ -9,6 +9,13 @@ class SignalHandler
|
||||
|
||||
private $callbacks;
|
||||
|
||||
/**
|
||||
* Constructor, should only be called once for each signal but can have
|
||||
* multiple handlers attached.
|
||||
*
|
||||
* @param integer $signo
|
||||
* @param array $callbacks
|
||||
*/
|
||||
public function __construct(int $signo, array $callbacks=[])
|
||||
{
|
||||
$this->signo = $signo;
|
||||
@ -21,11 +28,23 @@ class SignalHandler
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a handler to the signal
|
||||
*
|
||||
* @param callable $handler
|
||||
* @return void
|
||||
*/
|
||||
public function addHandler(callable $handler):void
|
||||
{
|
||||
$this->callbacks[] = $handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for signals
|
||||
*
|
||||
* @param int $signo
|
||||
* @return void
|
||||
*/
|
||||
public function onSignal($signo)
|
||||
{
|
||||
foreach ($this->callbacks as $callback) {
|
||||
|
@ -9,17 +9,33 @@ class SignalTrap
|
||||
|
||||
protected $trapped = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param integer $signo
|
||||
*/
|
||||
public function __construct(int $signo)
|
||||
{
|
||||
$this->signal = new Signal($signo);
|
||||
$this->signal->setHandler([ $this, "onSignal" ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal handler callback
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onSignal()
|
||||
{
|
||||
$this->trapped = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the signal has been received
|
||||
*
|
||||
* @param boolean $reset
|
||||
* @return boolean
|
||||
*/
|
||||
public function isTrapped($reset=true):bool
|
||||
{
|
||||
if ($this->trapped) {
|
||||
|
Reference in New Issue
Block a user