Skip to content

Commit

Permalink
Integrate Whoops into the core of the framework error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 11, 2013
1 parent 4612d11 commit 64f3a79
Show file tree
Hide file tree
Showing 5 changed files with 571 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"php": ">=5.3.7",
"classpreloader/classpreloader": "1.0.*",
"ircmaxell/password-compat": "1.0.*",
"filp/whoops": "1.0.0",
"monolog/monolog": "1.4.*",
"patchwork/utf8": "1.0.*",
"predis/predis": "0.*",
"predis/predis": "0.8.*",
"swiftmailer/swiftmailer": "4.3.*",
"symfony/browser-kit": "2.3.*",
"symfony/console": "2.3.*",
Expand Down
83 changes: 79 additions & 4 deletions src/Illuminate/Exception/ExceptionServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php namespace Illuminate\Exception;

use Closure;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Handler\JsonResponseHandler;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
use Symfony\Component\HttpKernel\Debug\ExceptionHandler as KernelHandler;

Expand Down Expand Up @@ -43,6 +46,8 @@ public function register()
});

$this->registerExceptionHandler();

$this->registerWhoops();
}

/**
Expand Down Expand Up @@ -72,11 +77,11 @@ protected function registerKernelHandlers()
*/
protected function registerExceptionHandler()
{
$app = $this->app;
list($me, $app) = array($this, $this->app);

$app['exception.function'] = function() use ($app)
$app['exception.function'] = function() use ($me, $app)
{
return function($exception) use ($app)
return function($exception) use ($me, $app)
{
$response = $app['exception']->handle($exception);

Expand All @@ -91,7 +96,7 @@ protected function registerExceptionHandler()
}
else
{
$app['kernel.exception']->handle($exception);
$me->displayException($exception);
}
};
};
Expand All @@ -114,6 +119,76 @@ protected function registerShutdownHandler()
});
}

/**
* Register the Whoops error display service.
*
* @return void
*/
protected function registerWhoops()
{
$this->registerWhoopsHandler();

$this->app['whoops'] = $this->app->share(function($app)
{
$whoops = new \Whoops\Run;

$whoops->allowQuit(false);

return $whoops->pushHandler($app['whoops.handler']);
});
}

/**
* Register the Whoops handler for the request.
*
* @return void
*/
protected function registerWhoopsHandler()
{
if ($this->app['request']->ajax() or $this->app->runningInConsole())
{
$this->app['whoops.handler'] = function() { return new JsonResponseHandler; };
}
else
{
$this->app['whoops.handler'] = function()
{
with($handler = new PrettyPageHandler)->setResourcesPath(__DIR__.'/resources');

return $handler;
};
}
}

/**
* Display the given exception.
*
* @param \Exception $exception
* @return void
*/
public function displayException($exception)
{
if ($this->app['config']['app.debug'])
{
return $this->displayWhoopsException($exception);
}

$this->app['kernel.exception']->handle($exception);
}

/**
* Display a exception using the Whoops library.
*
* @param \Exception $exception
* @return void
*/
protected function displayWhoopsException($exception)
{
ob_start(); $this->app['whoops']->handleException($exception);

with(new Response(ob_get_clean(), 500))->send();
}

/**
* Set the given Closure as the exception handler.
*
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Exception/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"require": {
"php": ">=5.3.0",
"illuminate/support": "4.0.x",
"symfony/http-foundation": "2.3.x",
"symfony/http-kernel": "2.3.*"
},
"require-dev": {
Expand Down
Loading

10 comments on commit 64f3a79

@sarunast
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so cool πŸ‘

@KevinCreel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@filp
Copy link
Contributor

@filp filp commented on 64f3a79 Apr 11, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ˜…

I'm super happy right now. Thanks!

@brunogaspar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff Filipe ;)

@tkaw220
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful πŸ‘

@bstrahija
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, been using it anyway ;)

@PhiloNL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! πŸ‘

@broucz
Copy link

@broucz broucz commented on 64f3a79 Apr 12, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So good feature out of the box, awesome once again πŸ‘

@Zizaco
Copy link

@Zizaco Zizaco commented on 64f3a79 Apr 12, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ‘

@kfriend
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great move. Whoop's exception display is much nicer!

Please sign in to comment.