diff --git a/composer.json b/composer.json index 9e4afff8..a835a04f 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": ">=5.3.0", - "illuminate/support": "~4.0", + "illuminate/support": "~4.1", "maximebf/debugbar": "dev-master" }, "autoload": { diff --git a/readme.md b/readme.md index a1374200..e2440cff 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -## Laravel Debugbar +## Laravel 4 Debugbar This is a package to integrate PHP Debug Bar (https://github.com/maximebf/php-debugbar) with Laravel. It includes a ServiceProvider to register the debugbar and attach it to the output. You can publish assets and configure it through Laravel. @@ -36,7 +36,7 @@ It also provides a Facade interface for easy logging Messages, Exceptions and Ti Require this package in your composer.json and run composer update (or run `composer require barryvdh/laravel-debugbar:dev-master` directly): - "barryvdh/laravel-debugbar": "dev-master" + "barryvdh/laravel-debugbar": "1.*" After updating composer, add the ServiceProvider to the providers array in app/config/app.php diff --git a/src/Barryvdh/Debugbar/DataCollector/SymfonyRouteCollector.php b/src/Barryvdh/Debugbar/DataCollector/SymfonyRouteCollector.php index d4acbb62..8a9b5315 100644 --- a/src/Barryvdh/Debugbar/DataCollector/SymfonyRouteCollector.php +++ b/src/Barryvdh/Debugbar/DataCollector/SymfonyRouteCollector.php @@ -137,4 +137,4 @@ public function getWidgets() } return $widgets; } -} +} \ No newline at end of file diff --git a/src/Barryvdh/Debugbar/LaravelDebugBar.php b/src/Barryvdh/Debugbar/LaravelDebugBar.php index 9339223f..cd94a0cc 100644 --- a/src/Barryvdh/Debugbar/LaravelDebugBar.php +++ b/src/Barryvdh/Debugbar/LaravelDebugBar.php @@ -149,11 +149,15 @@ public function boot(){ } if($this->shouldCollect('route')){ - if(class_exists('Illuminate\Routing\RouteCollection')){ +<<<<<<< HEAD + if(version_compare($app::VERSION, '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')); +>>>>>>> 658a1562f075b9431f013319f3c28432d8c1837c } if( $this->shouldCollect('log', true) ){ @@ -229,50 +233,45 @@ public function boot(){ $renderer->setBaseUrl(asset('packages/barryvdh/laravel-debugbar')); $renderer->setIncludeVendors($this->app['config']->get('laravel-debugbar::config.include_vendors', true)); - $this->addListener(); - $this->booted = true; } - public function shouldCollect($name, $default=false){ - return $this->app['config']->get('laravel-debugbar::config.collectors.'.$name, $default); - } - - protected function addListener(){ - +<<<<<<< HEAD + public function modifyResponse($request, $response){ $app = $this->app; - $debugbar = $this; - $this->app->after(function (Request $request, Response $response) use($app, $debugbar) - { - - if( $app->runningInConsole() or (!$app['config']->get('laravel-debugbar::config.enabled')) ){ - return; - } + if( $app->runningInConsole() or (!$app['config']->get('laravel-debugbar::config.enabled')) ){ + return $response; + } - /** @var \Illuminate\Session\SessionManager $sessionManager */ - $sessionManager = $app['session']; - $httpDriver = new SymfonyHttpDriver($sessionManager, $response); - $debugbar->setHttpDriver($httpDriver); + /** @var \Illuminate\Session\SessionManager $sessionManager */ + $sessionManager = $app['session']; + $httpDriver = new SymfonyHttpDriver($sessionManager, $response); + $this->setHttpDriver($httpDriver); - if($debugbar->shouldCollect('symfony_request', true) and !$debugbar->hasCollector('request')){ - $debugbar->addCollector(new SymfonyRequestCollector($request, $response, $app['session'], $app->make('Symfony\Component\HttpKernel\DataCollector\RequestDataCollector'))); - } + if($this->shouldCollect('symfony_request', true) and !$this->hasCollector('request')){ + $this->addCollector(new SymfonyRequestCollector($request, $response, $app['session'], $app->make('Symfony\Component\HttpKernel\DataCollector\RequestDataCollector'))); + } - if($response->isRedirection()){ - $debugbar->stackData(); - }elseif( $request->isXmlHttpRequest() and $app['config']->get('laravel-debugbar::config.capture_ajax', true)){ - $debugbar->sendDataInHeaders(); - }elseif( - ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) - || 'html' !== $request->getRequestFormat() - ){ - return; - }elseif($app['config']->get('laravel-debugbar::config.inject', true)){ - $debugbar->injectDebugbar($response); - } + if($response->isRedirection()){ + $this->stackData(); + }elseif( $request->isXmlHttpRequest() and $app['config']->get('laravel-debugbar::config.capture_ajax', true)){ + $this->sendDataInHeaders(); + }elseif( + ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) + || 'html' !== $request->getRequestFormat() + ){ + //Do nothing + }elseif($app['config']->get('laravel-debugbar::config.inject', true)){ + $this->injectDebugbar($response); + } + return $response; + } - }); +======= +>>>>>>> 658a1562f075b9431f013319f3c28432d8c1837c + public function shouldCollect($name, $default=false){ + return $this->app['config']->get('laravel-debugbar::config.collectors.'.$name, $default); } diff --git a/src/Barryvdh/Debugbar/Middleware.php b/src/Barryvdh/Debugbar/Middleware.php new file mode 100644 index 00000000..3491aaad --- /dev/null +++ b/src/Barryvdh/Debugbar/Middleware.php @@ -0,0 +1,74 @@ +app = $app; + $this->debugbar = $debugbar; + } + + /** + * Handles a Request to convert it to a Response. + * + * When $catch is true, the implementation must catch all exceptions + * and do its best to convert them to a Response instance. + * + * @param Request $request A Request instance + * @param integer $type The type of the request + * (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST) + * @param Boolean $catch Whether to catch exceptions or not + * + * @return Response A Response instance + * + * @throws \Exception When an Exception occurs during processing + * + * @api + */ + public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) + { + + $app = $this->app; + $debugbar = $this->debugbar; + + $response = $this->app->handle($request, $type, $catch); + + if( $app->runningInConsole() or (!$app['config']->get('laravel-debugbar::config.enabled')) ){ + return $response; + } + + /** @var \Illuminate\Session\SessionManager $sessionManager */ + $sessionManager = $app['session']; + $httpDriver = new SymfonyHttpDriver($sessionManager, $response); + $debugbar->setHttpDriver($httpDriver); + + if($debugbar->shouldCollect('symfony_request', true) and !$debugbar->hasCollector('request')){ + $debugbar->addCollector(new SymfonyRequestCollector($request, $response, $app['session'], $app->make('Symfony\Component\HttpKernel\DataCollector\RequestDataCollector'))); + } + + if($response->isRedirection()){ + $debugbar->stackData(); + }elseif( $request->isXmlHttpRequest() and $app['config']->get('laravel-debugbar::config.capture_ajax', true)){ + $debugbar->sendDataInHeaders(); + }elseif( + ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) + || 'html' !== $request->getRequestFormat() + ){ + //Do nothing + }elseif($app['config']->get('laravel-debugbar::config.inject', true)){ + $debugbar->injectDebugbar($response); + } + return $response; + } +} diff --git a/src/Barryvdh/Debugbar/ServiceProvider.php b/src/Barryvdh/Debugbar/ServiceProvider.php index ebcccc19..6f9b602d 100644 --- a/src/Barryvdh/Debugbar/ServiceProvider.php +++ b/src/Barryvdh/Debugbar/ServiceProvider.php @@ -52,6 +52,22 @@ public function register() }); $this->commands('command.debugbar.publish'); +<<<<<<< HEAD + $debugbar = $this->app['debugbar']; + $app = $this->app; + + if(version_compare($app::VERSION, '4.1', '>=')){ + $this->app->middleware('Barryvdh\Debugbar\Middleware', array($debugbar)); + }else{ + $this->app->after(function ($request, $response) use($debugbar) + { + $debugbar->modifyResponse($request, $response); + }); + } + +======= + $this->app->middleware('Barryvdh\Debugbar\Middleware', array($this->app['debugbar'])); +>>>>>>> 658a1562f075b9431f013319f3c28432d8c1837c } /**