Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ public function bootstrap(Application $app)

error_reporting(-1);

set_error_handler([$this, 'handleError']);

set_exception_handler([$this, 'handleException']);

register_shutdown_function([$this, 'handleShutdown']);
HandleExceptionsGlobal::register($this);

if (! $app->environment('testing')) {
ini_set('display_errors', 'Off');
Expand Down
79 changes: 79 additions & 0 deletions src/Illuminate/Foundation/Bootstrap/HandleExceptionsGlobal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace Illuminate\Foundation\Bootstrap;

use Throwable;

class HandleExceptionsGlobal
{
protected static $instance;

/**
* @var \Illuminate\Foundation\Bootstrap\HandleExceptions
*/
protected $handler;

protected function __construct()
{
set_error_handler([$this, 'handleError']);
set_exception_handler([$this, 'handleException']);
register_shutdown_function([$this, 'handleShutdown']);
}

/**
* Register a global exception handler.
*
* @param \Illuminate\Foundation\Bootstrap\HandleExceptions $handler
* @return void
*/
public static function register(HandleExceptions $handler)
{
if (! self::$instance) {
self::$instance = new self;
}

self::$instance->handler = $handler;
}

/**
* Report PHP deprecations, or 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
*/
public function handleError($level, $message, $file = '', $line = 0, $context = [])
{
$this->handler->handleError($level, $message, $file, $line, $context);
}

/**
* 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(Throwable $e)
{
$this->handler->handleException($e);
}

/**
* Handle the PHP shutdown event.
*
* @return void
*/
public function handleShutdown()
{
$this->handler->handleShutdown();
}
}
4 changes: 2 additions & 2 deletions tests/Support/SupportJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testJsonSerializable()

public $bar = 'not world';

public function jsonSerialize()
public function jsonSerialize(): array
{
return ['foo' => 'hello', 'bar' => 'world'];
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public function toJson($options = 0)
return json_encode(['foo' => 'hello', 'bar' => 'world'], $options);
}

public function jsonSerialize()
public function jsonSerialize(): array
{
return ['foo' => 'not hello', 'bar' => 'not world'];
}
Expand Down