mirror of
https://github.com/filp/whoops.git
synced 2026-09-13 19:26:21 +00:00
Merge pull request #327 from filp/remove-silex-1
Remove integration with Silex 1, fix #101
This commit is contained in:
@@ -31,13 +31,12 @@ For documentation on the stable version, see [branch `v1`](https://github.com/fi
|
||||
- Includes a pretty rad error page for your webapp projects
|
||||
- Includes the ability to [open referenced files directly in your editor and IDE](docs/Open%20Files%20In%20An%20Editor.md)
|
||||
- Includes handlers for different response formats (JSON, XML, SOAP)
|
||||
- Includes a Silex Service Provider for painless integration with [Silex](http://silex.sensiolabs.org/)
|
||||
- Easy to extend and integrate with existing libraries
|
||||
- Clean, well-structured & tested code-base
|
||||
|
||||
## Installing
|
||||
If you use Laravel 4, you already have Whoops. There are also community-provided instructions on how to integrate Whoops into
|
||||
[Silex](docs/Framework%20Integration.md#integrating-with-silex),
|
||||
[Silex 1](https://github.com/whoops-php/silex-1),
|
||||
[Silex 2](https://github.com/texthtml/whoops-silex),
|
||||
[Phalcon](https://github.com/whoops-php/phalcon),
|
||||
[Laravel 3](https://gist.github.com/hugomrdias/5169713#file-start-php),
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "filp/whoops",
|
||||
"license": "MIT",
|
||||
"description": "php error handling for cool kids",
|
||||
"keywords": ["library", "error", "handling", "exception", "silex-provider", "whoops", "zf2"],
|
||||
"keywords": ["library", "error", "handling", "exception", "whoops", "zf2"],
|
||||
"homepage": "https://github.com/filp/whoops",
|
||||
"authors": [
|
||||
{
|
||||
|
||||
@@ -1,37 +1,3 @@
|
||||
# Integrating with Silex
|
||||
|
||||
**whoops** comes packaged with a Silex Service Provider: `Whoops\Provider\Silex\WhoopsServiceProvider`. Using it
|
||||
in your existing Silex project is easy:
|
||||
|
||||
```php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Silex\Application;
|
||||
|
||||
// ... some awesome code here ...
|
||||
|
||||
if ($app['debug']) {
|
||||
$app->register(new Whoops\Provider\Silex\WhoopsServiceProvider());
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
$app->run();
|
||||
```
|
||||
|
||||
And that's about it. By default, you'll get the pretty error pages if something goes awry in your development
|
||||
environment, but you also have full access to the **whoops** library, obviously. For example, adding a new handler
|
||||
into your app is as simple as extending `whoops`:
|
||||
|
||||
```php
|
||||
$app['whoops'] = $app->extend('whoops', function ($whoops) {
|
||||
$whoops->pushHandler(new DeleteWholeProjectHandler());
|
||||
return $whoops;
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
# Contributing an integration with a framework
|
||||
|
||||
Lately we're prefering to keep integration libraries out of the Whoops core.
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*
|
||||
* NOTE: Requires silex/silex, can be installed with composer:
|
||||
*
|
||||
* $ composer require silex/silex:*
|
||||
*
|
||||
* Run this example file with the PHP 5.4 web server with:
|
||||
*
|
||||
* $ cd project_dir
|
||||
* $ php -S localhost:8080
|
||||
*
|
||||
* and access localhost:8080/examples/example-silex.php through your browser
|
||||
*
|
||||
* Or just run it through apache/nginx/what-have-yous as usual.
|
||||
*/
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
use Silex\Application;
|
||||
use Whoops\Provider\Silex\WhoopsServiceProvider;
|
||||
|
||||
$app = new Application();
|
||||
$app['debug'] = true;
|
||||
|
||||
if ($app['debug']) {
|
||||
$app->register(new WhoopsServiceProvider());
|
||||
}
|
||||
|
||||
$app->get('/', function () use ($app) {
|
||||
throw new RuntimeException("Oh no!");
|
||||
});
|
||||
|
||||
$app->run();
|
||||
@@ -1,111 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Whoops - php errors for cool kids
|
||||
* @author Filipe Dobreira <http://github.com/filp>
|
||||
*/
|
||||
|
||||
namespace Whoops\Provider\Silex;
|
||||
|
||||
use RuntimeException;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Whoops\Handler\Handler;
|
||||
use Whoops\Handler\PlainTextHandler;
|
||||
use Whoops\Handler\PrettyPageHandler;
|
||||
use Whoops\Run;
|
||||
|
||||
class WhoopsServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @param Application $app
|
||||
*/
|
||||
public function register(Application $app)
|
||||
{
|
||||
// There's only ever going to be one error page...right?
|
||||
$app['whoops.error_page_handler'] = $app->share(function () {
|
||||
if (PHP_SAPI === 'cli') {
|
||||
return new PlainTextHandler();
|
||||
} else {
|
||||
return new PrettyPageHandler();
|
||||
}
|
||||
});
|
||||
|
||||
// Retrieves info on the Silex environment and ships it off
|
||||
// to the PrettyPageHandler's data tables:
|
||||
// This works by adding a new handler to the stack that runs
|
||||
// before the error page, retrieving the shared page handler
|
||||
// instance, and working with it to add new data tables
|
||||
$app['whoops.silex_info_handler'] = $app->protect(function () use ($app) {
|
||||
try {
|
||||
/** @var Request $request */
|
||||
$request = $app['request'];
|
||||
} catch (RuntimeException $e) {
|
||||
// This error occurred too early in the application's life
|
||||
// and the request instance is not yet available.
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Handler $errorPageHandler */
|
||||
$errorPageHandler = $app["whoops.error_page_handler"];
|
||||
|
||||
if ($errorPageHandler instanceof PrettyPageHandler) {
|
||||
/** @var PrettyPageHandler $errorPageHandler */
|
||||
|
||||
// General application info:
|
||||
$errorPageHandler->addDataTable('Silex Application', array(
|
||||
'Charset' => $app['charset'],
|
||||
'Locale' => $app['locale'],
|
||||
'Route Class' => $app['route_class'],
|
||||
'Dispatcher Class' => $app['dispatcher_class'],
|
||||
'Application Class' => get_class($app),
|
||||
));
|
||||
|
||||
// Request info:
|
||||
$errorPageHandler->addDataTable('Silex Application (Request)', array(
|
||||
'URI' => $request->getUri(),
|
||||
'Request URI' => $request->getRequestUri(),
|
||||
'Path Info' => $request->getPathInfo(),
|
||||
'Query String' => $request->getQueryString() ?: '<none>',
|
||||
'HTTP Method' => $request->getMethod(),
|
||||
'Script Name' => $request->getScriptName(),
|
||||
'Base Path' => $request->getBasePath(),
|
||||
'Base URL' => $request->getBaseUrl(),
|
||||
'Scheme' => $request->getScheme(),
|
||||
'Port' => $request->getPort(),
|
||||
'Host' => $request->getHost(),
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
$app['whoops'] = $app->share(function () use ($app) {
|
||||
$run = new Run();
|
||||
$run->allowQuit(false);
|
||||
$run->pushHandler($app['whoops.error_page_handler']);
|
||||
$run->pushHandler($app['whoops.silex_info_handler']);
|
||||
return $run;
|
||||
});
|
||||
|
||||
$app->error(function ($e) use ($app) {
|
||||
$method = Run::EXCEPTION_HANDLER;
|
||||
|
||||
ob_start();
|
||||
$app['whoops']->$method($e);
|
||||
$response = ob_get_clean();
|
||||
$code = $e instanceof HttpException ? $e->getStatusCode() : 500;
|
||||
|
||||
return new Response($response, $code);
|
||||
});
|
||||
|
||||
$app['whoops']->register();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Silex\ServiceProviderInterface::boot
|
||||
*/
|
||||
public function boot(Application $app)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user