<?phpnamespaceIlluminate\Foundation\Bootstrap;useException;useErrorException;useIlluminate\Contracts\Debug\ExceptionHandler;useIlluminate\Contracts\Foundation\Application;useSymfony\Component\Console\Output\ConsoleOutput;useSymfony\Component\Debug\Exception\FatalErrorException;useSymfony\Component\Debug\Exception\FatalThrowableError;classHandleExceptions{/**
* The application instance.
*
* @var \Illuminate\Contracts\Foundation\Application
*/protected$app;/**
* Bootstrap the given application.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/publicfunctionbootstrap(Application $app){$this->app=$app;error_reporting(-1);set_error_handler([$this,'handleError']);set_exception_handler([$this,'handleException']);register_shutdown_function([$this,'handleShutdown']);if(!$app->environment('testing')){ini_set('display_errors','Off');}}/**
* Convert PHP errors to ErrorException instances.
*
* @param int $level
* @param string $message
* @param string $file
* @param int $line
* @param array $context
* @return void
*
* @throws \ErrorException
*/publicfunctionhandleError($level,$message,$file='',$line=0,$context=[]){if(error_reporting()&$level){thrownewErrorException($message,0,$level,$file,$line);}}/**
* Handle an uncaught exception from the application.
*
* Note: Most exceptions can be handled via the try / catch block in
* the HTTP and Console kernels. But, fatal error exceptions must
* be handled differently since they are not normal exceptions.
*
* @param \Throwable $e
* @return void
*/publicfunctionhandleException($e){if(!$einstanceofException){$e=newFatalThrowableError($e);}try{$this->getExceptionHandler()->report($e);}catch(Exception$e){//}if($this->app->runningInConsole()){$this->renderForConsole($e);}else{$this->renderHttpResponse($e);}}/**
* Render an exception to the console.
*
* @param \Exception $e
* @return void
*/protectedfunctionrenderForConsole(Exception $e){$this->getExceptionHandler()->renderForConsole(newConsoleOutput,$e);}/**
* Render an exception as an HTTP response and send it.
*
* @param \Exception $e
* @return void
*/protectedfunctionrenderHttpResponse(Exception $e){$this->getExceptionHandler()->render($this->app['request'],$e)->send();}/**
* Handle the PHP shutdown event.
*
* @return void
*/publicfunctionhandleShutdown(){if(!is_null($error=error_get_last())&&$this->isFatal($error['type'])){$this->handleException($this->fatalExceptionFromError($error,0));}}/**
* Create a new fatal exception instance from an error array.
*
* @param array $error
* @param int|null $traceOffset
* @return \Symfony\Component\Debug\Exception\FatalErrorException
*/protectedfunctionfatalExceptionFromError(array$error,$traceOffset=null){returnnewFatalErrorException($error['message'],$error['type'],0,$error['file'],$error['line'],$traceOffset);}/**
* Determine if the error type is fatal.
*
* @param int $type
* @return bool
*/protectedfunctionisFatal($type){returnin_array($type,[E_COMPILE_ERROR,E_CORE_ERROR,E_ERROR,E_PARSE]);}/**
* Get an instance of the exception handler.
*
* @return \Illuminate\Contracts\Debug\ExceptionHandler
*/protectedfunctiongetExceptionHandler(){return$this->app->make(ExceptionHandler::class);}}