Вход Регистрация
Файл: gapps/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
Строк: 217
<?php

namespace IlluminateFoundationBootstrap;

use 
Exception;
use 
ErrorException;
use 
IlluminateContractsFoundationApplication;
use 
SymfonyComponentConsoleOutputConsoleOutput;
use 
SymfonyComponentDebugExceptionFatalErrorException;
use 
SymfonyComponentDebugExceptionFatalThrowableError;

class 
HandleExceptions
{
    
/**
     * The application instance.
     *
     * @var IlluminateContractsFoundationApplication
     */
    
protected $app;

    
/**
     * Bootstrap the given application.
     *
     * @param  IlluminateContractsFoundationApplication  $app
     * @return void
     */
    
public function bootstrap(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 a PHP error to an ErrorException.
     *
     * @param  int  $level
     * @param  string  $message
     * @param  string  $file
     * @param  int  $line
     * @param  array  $context
     * @return void
     *
     * @throws ErrorException
     */
    
public function handleError($level$message$file ''$line 0$context = [])
    {
        if (
error_reporting() & $level) {
            throw new 
ErrorException($message0$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
     */
    
public function handleException($e)
    {
        if (! 
$e instanceof Exception) {
            
$e = new FatalThrowableError($e);
        }

        
$this->getExceptionHandler()->report($e);

        if (
$this->app->runningInConsole()) {
            
$this->renderForConsole($e);
        } else {
            
$this->renderHttpResponse($e);
        }
    }

    
/**
     * Render an exception to the console.
     *
     * @param  Exception  $e
     * @return void
     */
    
protected function renderForConsole(Exception $e)
    {
        
$this->getExceptionHandler()->renderForConsole(new ConsoleOutput$e);
    }

    
/**
     * Render an exception as an HTTP response and send it.
     *
     * @param  Exception  $e
     * @return void
     */
    
protected function renderHttpResponse(Exception $e)
    {
        
$this->getExceptionHandler()->render($this->app['request'], $e)->send();
    }

    
/**
     * Handle the PHP shutdown event.
     *
     * @return void
     */
    
public function handleShutdown()
    {
        if (! 
is_null($error error_get_last()) && $this->isFatal($error['type'])) {
            
$this->handleException($this->fatalExceptionFromError($error0));
        }
    }

    
/**
     * Create a new fatal exception instance from an error array.
     *
     * @param  array  $error
     * @param  int|null  $traceOffset
     * @return SymfonyComponentDebugExceptionFatalErrorException
     */
    
protected function fatalExceptionFromError(array $error$traceOffset null)
    {
        return new 
FatalErrorException(
            
$error['message'], $error['type'], 0$error['file'], $error['line'], $traceOffset
        
);
    }

    
/**
     * Determine if the error type is fatal.
     *
     * @param  int  $type
     * @return bool
     */
    
protected function isFatal($type)
    {
        return 
in_array($type, [E_ERRORE_CORE_ERRORE_COMPILE_ERRORE_PARSE]);
    }

    
/**
     * Get an instance of the exception handler.
     *
     * @return IlluminateContractsDebugExceptionHandler
     */
    
protected function getExceptionHandler()
    {
        return 
$this->app->make('IlluminateContractsDebugExceptionHandler');
    }
}
Онлайн: 0
Реклама