Device stubs and exceptions added
This commit is contained in:
30
lib/Exception/Handler/ConsoleHandler.php
Normal file
30
lib/Exception/Handler/ConsoleHandler.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace NoccyLabs\Gpio\Exception\Handler;
|
||||
|
||||
use NoccyLabs\Gpio\Exception\GpioException;
|
||||
|
||||
class ConsoleExceptionHandler
|
||||
{
|
||||
protected $last;
|
||||
|
||||
public function register()
|
||||
{
|
||||
$this->last = set_exception_handler( array($this, "onException") );
|
||||
}
|
||||
|
||||
public function onException(Exception $exception)
|
||||
{
|
||||
if (is_callable($this->last)) {
|
||||
call_user_func($this->last, $exception);
|
||||
}
|
||||
if ($exception instanceof GpioException) {
|
||||
$pin = $exception->getPin();
|
||||
if ($pin) {
|
||||
$pin->dumpState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user