48 lines
813 B
PHP
48 lines
813 B
PHP
<?php
|
|
|
|
namespace NoccyLabs\Ipc\Signal;
|
|
|
|
|
|
class SignalTrap
|
|
{
|
|
protected $signal;
|
|
|
|
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) {
|
|
$reset && ($this->trapped = false);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
} |