Initial commit
This commit is contained in:
32
src/Signal/SignalTrap.php
Normal file
32
src/Signal/SignalTrap.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Ipc\Signal;
|
||||
|
||||
|
||||
class SignalTrap
|
||||
{
|
||||
protected $signal;
|
||||
|
||||
protected $trapped = false;
|
||||
|
||||
public function __construct(int $signo)
|
||||
{
|
||||
$this->signal = new Signal($signo);
|
||||
$this->signal->setHandler([ $this, "onSignal" ]);
|
||||
}
|
||||
|
||||
public function onSignal()
|
||||
{
|
||||
$this->trapped = true;
|
||||
}
|
||||
|
||||
public function isTrapped($reset=true):bool
|
||||
{
|
||||
if ($this->trapped) {
|
||||
$reset && ($this->trapped = false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user