31 lines
		
	
	
		
			628 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			628 B
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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();
 | 
						|
            }
 | 
						|
        } 
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
}
 |