php-linux-gpio/lib/Exception/Handler/ConsoleHandler.php

31 lines
628 B
PHP
Raw Normal View History

2014-06-06 18:32:40 +00:00
<?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();
}
}
}
}