From d4bc7b1625e7f73a0a4f101866ebb12679271ae5 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Sat, 10 Jan 2015 15:50:21 +0100 Subject: [PATCH] Start of Laravel 5 changes Remove some checks, change configuration, remove old middleware. --- composer.json | 10 +-- {src/config => config}/config.php | 0 readme.md | 6 +- src/Controllers/OpenHandlerController.php | 3 +- .../IlluminateRouteCollector.php | 2 +- src/LaravelDebugBar.php | 63 ++++++++----------- src/Middleware/Stack.php | 38 ----------- src/ServiceProvider.php | 59 ++--------------- 8 files changed, 41 insertions(+), 140 deletions(-) rename {src/config => config}/config.php (100%) delete mode 100644 src/Middleware/Stack.php diff --git a/composer.json b/composer.json index 294dab6a..043d0049 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,6 @@ "description": "PHP Debugbar integration for Laravel", "keywords": ["laravel", "debugbar", "profiler", "debug", "webprofiler"], "license": "MIT", - "authors": [ { "name": "Barry vd. Heuvel", @@ -11,9 +10,9 @@ } ], "require": { - "php": ">=5.3.0", - "illuminate/support": "4.*|5.0.*", - "symfony/finder": "~2.3", + "php": ">=5.4.0", + "illuminate/support": "5.0.*", + "symfony/finder": "~2.6", "maximebf/debugbar": "~1.10.2" }, "autoload": { @@ -28,5 +27,6 @@ "branch-alias": { "dev-master": "1.8-dev" } - } + }, + "minimum-stability": "dev" } diff --git a/src/config/config.php b/config/config.php similarity index 100% rename from src/config/config.php rename to config/config.php diff --git a/readme.md b/readme.md index 65746019..ce517c74 100644 --- a/readme.md +++ b/readme.md @@ -3,7 +3,7 @@ [![Latest Stable Version](https://poser.pugx.org/barryvdh/laravel-debugbar/version.png)](https://packagist.org/packages/barryvdh/laravel-debugbar) [![Total Downloads](https://poser.pugx.org/barryvdh/laravel-debugbar/d/total.png)](https://packagist.org/packages/barryvdh/laravel-debugbar) -This is a package to integrate [PHP Debug Bar](http://phpdebugbar.com/) with Laravel. +This is a package to integrate [PHP Debug Bar](http://phpdebugbar.com/) with Laravel 5. It includes a ServiceProvider to register the debugbar and attach it to the output. You can publish assets and configure it through Laravel. It bootstraps some Collectors to work with Laravel and implements a couple custom DataCollectors, specific for Laravel. It is configured to display Redirects and (jQuery) Ajax Requests. (Shown in a dropdown) @@ -58,9 +58,7 @@ If you want to use the facade to log messages, add this to your facades in app.p 'Debugbar' => 'Barryvdh\Debugbar\Facade', ``` -~~You need to publish the assets from this package.~~ Since 1.7, you don't need to publish the assets anymore. - -The profiler is enabled by default, if you have app.debug=true. You can override that in the config files. +The profiler is enabled by default, if you have app.debug=true. You can override that in the config (`debugbar.enabled`). See more options in `config/config.php` You can also set in your config if you want to include/exclude the vendor files also (FontAwesome, Highlight.js and jQuery). If you already use them in your site, set it to false. You can also only display the js of css vendors, by setting it to 'js' or 'css'. (Highlight.js requires both css + js, so set to `true` for syntax highlighting) diff --git a/src/Controllers/OpenHandlerController.php b/src/Controllers/OpenHandlerController.php index c12001a5..db9cce74 100644 --- a/src/Controllers/OpenHandlerController.php +++ b/src/Controllers/OpenHandlerController.php @@ -2,8 +2,9 @@ use DebugBar\OpenHandler; use Illuminate\Http\Response; +use Illuminate\Routing\Controller; -class OpenHandlerController extends BaseController +class OpenHandlerController extends Controller { public function handle() { diff --git a/src/DataCollector/IlluminateRouteCollector.php b/src/DataCollector/IlluminateRouteCollector.php index a2774342..315b80f3 100644 --- a/src/DataCollector/IlluminateRouteCollector.php +++ b/src/DataCollector/IlluminateRouteCollector.php @@ -172,7 +172,7 @@ public function getWidgets() "default" => "{}" ) ); - if (Config::get('laravel-debugbar::config.options.route.label', true)) { + if (Config::get('debugbar.options.route.label', true)) { $widgets['currentroute'] = array( "icon" => "share", "tooltip" => "Route", diff --git a/src/LaravelDebugBar.php b/src/LaravelDebugBar.php index d35bbfa0..efb54259 100644 --- a/src/LaravelDebugBar.php +++ b/src/LaravelDebugBar.php @@ -82,7 +82,7 @@ public function __construct($app = null) */ public function enable() { - $this->app['config']->set('laravel-debugbar::config.enabled', true); + $this->app['config']->set('debugbar.enabled', true); if (!$this->booted) { $this->boot(); } @@ -127,7 +127,7 @@ function () use ($debugbar, $startTime) { ); //Check if App::before is already called.. - if ($this->checkVersion('4.1-dev', '>=') && $this->app->isBooted()) { + if ($this->app->isBooted()) { $debugbar->startMeasure('application', 'Application'); } else { $this->app['router']->before( @@ -151,16 +151,9 @@ function () use ($debugbar) { try { $exceptionCollector = new ExceptionsCollector(); $exceptionCollector->setChainExceptions( - $this->app['config']->get('laravel-debugbar::config.options.exceptions.chain', true) + $this->app['config']->get('debugbar.options.exceptions.chain', true) ); $this->addCollector($exceptionCollector); - if ($this->checkVersion('5.0-dev', '<')) { - $this->app->error( - function (Exception $exception) use ($exceptionCollector) { - $exceptionCollector->addException($exception); - } - ); - } } catch (\Exception $e) { } } @@ -191,7 +184,7 @@ function (Exception $exception) use ($exceptionCollector) { if ($this->shouldCollect('views', true) and isset($this->app['events'])) { try { - $collectData = $this->app['config']->get('laravel-debugbar::config.options.views.data', true); + $collectData = $this->app['config']->get('debugbar.options.views.data', true); $this->addCollector(new ViewCollector($collectData)); $this->app['events']->listen( 'composing:*', @@ -210,11 +203,7 @@ function ($view) use ($debugbar) { if ($this->shouldCollect('route')) { try { - if ($this->checkVersion('4.1', '>=')) { - $this->addCollector($this->app->make('Barryvdh\Debugbar\DataCollector\IlluminateRouteCollector')); - } else { - $this->addCollector($this->app->make('Barryvdh\Debugbar\DataCollector\SymfonyRouteCollector')); - } + $this->addCollector($this->app->make('Barryvdh\Debugbar\DataCollector\IlluminateRouteCollector')); } catch (\Exception $e) { $this->addException( new Exception( @@ -265,7 +254,7 @@ function ($level, $message, $context) use ($logger) { if ($this->shouldCollect('db', true) and isset($this->app['db'])) { $db = $this->app['db']; if ($debugbar->hasCollector('time') && $this->app['config']->get( - 'laravel-debugbar::config.options.db.timeline', + 'debugbar.options.db.timeline', false ) ) { @@ -275,20 +264,20 @@ function ($level, $message, $context) use ($logger) { } $queryCollector = new QueryCollector($timeCollector); - if ($this->app['config']->get('laravel-debugbar::config.options.db.with_params')) { + if ($this->app['config']->get('debugbar.options.db.with_params')) { $queryCollector->setRenderSqlWithParams(true); } - if ($this->app['config']->get('laravel-debugbar::config.options.db.backtrace')) { + if ($this->app['config']->get('debugbar.options.db.backtrace')) { $queryCollector->setFindSource(true); } - if ($this->app['config']->get('laravel-debugbar::config.options.db.explain.enabled')) { - $types = $this->app['config']->get('laravel-debugbar::config.options.db.explain.types'); + if ($this->app['config']->get('debugbar.options.db.explain.enabled')) { + $types = $this->app['config']->get('debugbar.options.db.explain.types'); $queryCollector->setExplainSource(true, $types); } - if ($this->app['config']->get('laravel-debugbar::config.options.db.hints', true)) { + if ($this->app['config']->get('debugbar.options.db.hints', true)) { $queryCollector->setShowHints(true); } @@ -316,7 +305,7 @@ function ($query, $bindings, $time, $connectionName) use ($db, $queryCollector) try { $mailer = $this->app['mailer']->getSwiftMailer(); $this->addCollector(new SwiftMailCollector($mailer)); - if ($this->app['config']->get('laravel-debugbar::config.options.mail.full_log') and $this->hasCollector( + if ($this->app['config']->get('debugbar.options.mail.full_log') and $this->hasCollector( 'messages' ) ) { @@ -333,7 +322,7 @@ function ($query, $bindings, $time, $connectionName) use ($db, $queryCollector) if ($this->shouldCollect('logs', false)) { try { - $file = $this->app['config']->get('laravel-debugbar::config.options.logs.file'); + $file = $this->app['config']->get('debugbar.options.logs.file'); $this->addCollector(new LogsCollector($file)); } catch (\Exception $e) { $this->addException( @@ -351,7 +340,7 @@ function ($query, $bindings, $time, $connectionName) use ($db, $queryCollector) try { $authCollector = new AuthCollector($app['auth']); $authCollector->setShowName( - $this->app['config']->get('laravel-debugbar::config.options.auth.show_name') + $this->app['config']->get('debugbar.options.auth.show_name') ); $this->addCollector($authCollector); } catch (\Exception $e) { @@ -364,15 +353,15 @@ function ($query, $bindings, $time, $connectionName) use ($db, $queryCollector) } $renderer = $this->getJavascriptRenderer(); - $renderer->setIncludeVendors($this->app['config']->get('laravel-debugbar::config.include_vendors', true)); - $renderer->setBindAjaxHandlerToXHR($app['config']->get('laravel-debugbar::config.capture_ajax', true)); + $renderer->setIncludeVendors($this->app['config']->get('debugbar.include_vendors', true)); + $renderer->setBindAjaxHandlerToXHR($app['config']->get('debugbar.capture_ajax', true)); $this->booted = true; } public function shouldCollect($name, $default = false) { - return $this->app['config']->get('laravel-debugbar::config.collectors.' . $name, $default); + return $this->app['config']->get('debugbar.collectors.' . $name, $default); } /** @@ -509,7 +498,7 @@ public function modifyResponse($request, $response) } } elseif ( ($request->isXmlHttpRequest() || $request->wantsJson()) and - $app['config']->get('laravel-debugbar::config.capture_ajax', true) + $app['config']->get('debugbar.capture_ajax', true) ) { try { $this->sendDataInHeaders(true); @@ -527,7 +516,7 @@ public function modifyResponse($request, $response) } catch (\Exception $e) { $app['log']->error('Debugbar exception: ' . $e->getMessage()); } - } elseif ($app['config']->get('laravel-debugbar::config.inject', true)) { + } elseif ($app['config']->get('debugbar.inject', true)) { try { $this->injectDebugbar($response); } catch (\Exception $e) { @@ -547,7 +536,7 @@ public function modifyResponse($request, $response) */ public function isEnabled() { - return value($this->app['config']->get('laravel-debugbar::config.enabled')); + return value($this->app['config']->get('debugbar.enabled')); } /** @@ -635,7 +624,7 @@ public function injectDebugbar(Response $response) */ public function disable() { - $this->app['config']->set('laravel-debugbar::config.enabled', false); + $this->app['config']->set('debugbar.enabled', false); } /** @@ -764,23 +753,23 @@ protected function checkVersion($version, $operator = ">=") protected function selectStorage(DebugBar $debugbar) { $config = $this->app['config']; - if ($config->get('laravel-debugbar::config.storage.enabled')) { - $driver = $config->get('laravel-debugbar::config.storage.driver', 'file'); + if ($config->get('debugbar.storage.enabled')) { + $driver = $config->get('debugbar.storage.driver', 'file'); switch ($driver) { case 'pdo': - $connection = $config->get('laravel-debugbar::config.storage.connection'); + $connection = $config->get('debugbar.storage.connection'); $table = $this->app['db']->getTablePrefix() . 'phpdebugbar'; $pdo = $this->app['db']->connection($connection)->getPdo(); $storage = new PdoStorage($pdo, $table); break; case 'redis': - $connection = $config->get('laravel-debugbar::config.storage.connection'); + $connection = $config->get('debugbar.storage.connection'); $storage = new RedisStorage($this->app['redis']->connection($connection)); break; case 'file': default: - $path = $config->get('laravel-debugbar::config.storage.path'); + $path = $config->get('debugbar.storage.path'); $storage = new FilesystemStorage($this->app['files'], $path); break; } diff --git a/src/Middleware/Stack.php b/src/Middleware/Stack.php deleted file mode 100644 index 3debbead..00000000 --- a/src/Middleware/Stack.php +++ /dev/null @@ -1,38 +0,0 @@ -kernel = $kernel; - $this->app = $app; - } - - /** - * {@inheritdoc} - */ - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) - { - /** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */ - $debugbar = $this->app['debugbar']; - - /** @var \Illuminate\Http\Response $response */ - $response = $this->kernel->handle($request, $type, $catch); - - return $debugbar->modifyResponse($request, $response); - } -} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index e7d94fac..4d29c658 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -18,21 +18,7 @@ public function boot() { $app = $this->app; - $this->registerConfiguration(); - - if ($app->runningInConsole()) { - if ($this->app['config']->get('laravel-debugbar::config.capture_console') && method_exists($app, 'shutdown')) { - $app->shutdown( - function ($app) { - /** @var LaravelDebugbar $debugbar */ - $debugbar = $app['debugbar']; - $debugbar->collectConsole(); - } - ); - } else { - $this->app['config']->set('laravel-debugbar::config.enabled', false); - } - } elseif (!$this->shouldUseMiddleware()) { + if (!$app->runningInConsole()) { $app['router']->after( function ($request, $response) use ($app) { /** @var LaravelDebugbar $debugbar */ @@ -66,7 +52,7 @@ function ($request, $response) use ($app) { ) ); - if ($this->app['config']->get('laravel-debugbar::config.enabled')) { + if ($this->app['config']->get('debugbar.enabled')) { /** @var LaravelDebugbar $debugbar */ $debugbar = $this->app['debugbar']; $debugbar->boot(); @@ -80,6 +66,8 @@ function ($request, $response) use ($app) { */ public function register() { + $this->app['config']->set('debugbar', require __DIR__ .'/../config/config.php')); + $this->app->alias( 'DebugBar\DataFormatter\DataFormatter', 'DebugBar\DataFormatter\DataFormatterInterface' @@ -97,12 +85,6 @@ function ($app) { } ); - $this->app['command.debugbar.publish'] = $this->app->share( - function ($app) { - return new Console\PublishCommand(); - } - ); - $this->app['command.debugbar.clear'] = $this->app->share( function ($app) { return new Console\ClearCommand($app['debugbar']); @@ -110,37 +92,6 @@ function ($app) { ); $this->commands(array('command.debugbar.publish', 'command.debugbar.clear')); - - if ($this->shouldUseMiddleware()) { - $this->app->middleware('Barryvdh\Debugbar\Middleware\Stack', array($this->app)); - } - } - - /** - * Register configuration files, with L5 fallback - */ - protected function registerConfiguration() - { - // Is it possible to register the config? - if (method_exists($this->app['config'], 'package')) { - $this->app['config']->package('barryvdh/laravel-debugbar', __DIR__ . '/config'); - } else { - // Load the config for now.. - $config = $this->app['files']->getRequire(__DIR__ .'/config/config.php'); - $this->app['config']->set('laravel-debugbar::config', $config); - } - } - - /** - * Detect if the Middelware should be used. - * - * @return bool - */ - protected function shouldUseMiddleware() - { - $app = $this->app; - $version = $app::VERSION; - return !$app->runningInConsole() && version_compare($version, '4.1-dev', '>=') && version_compare($version, '5.0-dev', '<'); } /** @@ -150,6 +101,6 @@ protected function shouldUseMiddleware() */ public function provides() { - return array('debugbar', 'command.debugbar.publish', 'command.debugbar.clear'); + return array('debugbar', 'command.debugbar.clear'); } }