Skip to content

Commit

Permalink
Add middleware for 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Dec 15, 2013
1 parent 053633e commit 39e6be1
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 40 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.3.0",
"illuminate/support": "~4.0",
"illuminate/support": "~4.1",
"maximebf/debugbar": "dev-master"
},
"autoload": {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ public function getWidgets()
}
return $widgets;
}
}
}
71 changes: 35 additions & 36 deletions src/Barryvdh/Debugbar/LaravelDebugBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) ){
Expand Down Expand Up @@ -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);
}


Expand Down
74 changes: 74 additions & 0 deletions src/Barryvdh/Debugbar/Middleware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php namespace Barryvdh\Debugbar;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Barryvdh\Debugbar\DataCollector\SymfonyRequestCollector;

class Middleware implements HttpKernelInterface {


/**
* Create a new debugbar middleware instance
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $app
* @param LaravelDebugbar $debugbar
*/
public function __construct(HttpKernelInterface $app, LaravelDebugbar $debugbar)
{
$this->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;
}
}
16 changes: 16 additions & 0 deletions src/Barryvdh/Debugbar/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit 39e6be1

Please sign in to comment.