Skip to content

Commit

Permalink
Merge Lumen together
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Jul 9, 2015
1 parent 6602b11 commit 331cb3f
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 287 deletions.
19 changes: 18 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ composer require barryvdh/laravel-debugbar
After updating composer, add the ServiceProvider to the providers array in config/app.php
> If you use a catch-all/fallback route, make sure you load the Debugbar ServiceProvider before your own App ServiceProviders.
### Laravel 5.x:

```
'Barryvdh\Debugbar\ServiceProvider',
```
Expand All @@ -60,6 +62,7 @@ If you want to use the facade to log messages, add this to your facades in app.p
'Debugbar' => 'Barryvdh\Debugbar\Facade',
```


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/debugbar.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)
Expand All @@ -70,7 +73,21 @@ Copy the package config to your local config with the publish command:
php artisan vendor:publish
```

You can also disable/enable the loggers you want. You can also use the IoC container to add extra loggers. (`$app['debugbar']->addCollector(new MyDataCollector)`)
### Lumen:

For Lumen, register a different Provider in `bootstrap/app.php`:

```
$app->register(Barryvdh\Debugbar\LumenServiceProvider::class);
```

To change the configuration, copy the file to your config folder and enable it:

```
$app->configure('debugbar');
```

## Usage

You can now add messages using the Facade (when added), using the PSR-3 levels (debug, info, notice, warning, error, critical, alert, emergency):

Expand Down
76 changes: 51 additions & 25 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use DebugBar\Storage\RedisStorage;
use Exception;

use Illuminate\Contracts\Foundation\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -66,7 +67,14 @@ class LaravelDebugbar extends DebugBar
protected $booted = false;

/**
* @param \Illuminate\Foundation\Application $app
* True when this is a Lumen application
*
* @var bool
*/
protected $is_lumen = false;

/**
* @param Application $app
*/
public function __construct($app = null)
{
Expand All @@ -75,6 +83,7 @@ public function __construct($app = null)
}
$this->app = $app;
$this->version = $app->version();
$this->is_lumen = str_contains($this->version, 'Lumen');
}

/**
Expand Down Expand Up @@ -103,50 +112,60 @@ public function boot()

/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugbar */
$debugbar = $this;
/** @var \Illuminate\Foundation\Application $app */

/** @var Application $app */
$app = $this->app;

$this->selectStorage($debugbar);

if ($this->shouldCollect('phpinfo', true)) {
$this->addCollector(new PhpInfoCollector());
}

if ($this->shouldCollect('messages', true)) {
$this->addCollector(new MessagesCollector());
}

if ($this->shouldCollect('time', true)) {
$startTime = defined('LARAVEL_START') ? LARAVEL_START : null;
$this->addCollector(new TimeDataCollector($startTime));

$this->app->booted(
function () use ($debugbar, $startTime) {
if ($startTime) {
$debugbar['time']->addMeasure('Booting', $startTime, microtime(true));
}
}
);

//Check if App::before is already called..
if ($this->app->isBooted()) {
if ($this->isLumen()) {
$debugbar->startMeasure('application', 'Application');
} else {
$this->app['router']->before(
function () use ($debugbar) {
$debugbar->startMeasure('application', 'Application');
}
$this->app->booted(
function () use ($debugbar, $startTime) {
if ($startTime) {
$debugbar['time']->addMeasure('Booting', $startTime, microtime(true));
}
}
);
}

$this->app['router']->after(
function () use ($debugbar) {
$debugbar->stopMeasure('application');
$debugbar->startMeasure('after', 'After application');
//Check if App::before is already called..
if ($this->app->isBooted()) {
$debugbar->startMeasure('application', 'Application');
} else {
$this->app['router']->before(
function () use ($debugbar) {
$debugbar->startMeasure('application', 'Application');
}
);
}
);

$this->app['router']->after(
function () use ($debugbar) {
$debugbar->stopMeasure('application');
$debugbar->startMeasure('after', 'After application');
}
);
}

}

if ($this->shouldCollect('memory', true)) {
$this->addCollector(new MemoryCollector());
}

if ($this->shouldCollect('exceptions', true)) {
try {
$exceptionCollector = new ExceptionsCollector();
Expand All @@ -157,9 +176,11 @@ function () use ($debugbar) {
} catch (\Exception $e) {
}
}

if ($this->shouldCollect('laravel', false)) {
$this->addCollector(new LaravelCollector($this->app));
}

if ($this->shouldCollect('default_request', false)) {
$this->addCollector(new RequestDataCollector());
}
Expand Down Expand Up @@ -201,7 +222,7 @@ function ($view) use ($debugbar) {
}
}

if ($this->shouldCollect('route')) {
if (!$this->isLumen() && $this->shouldCollect('route')) {
try {
$this->addCollector($this->app->make('Barryvdh\Debugbar\DataCollector\IlluminateRouteCollector'));
} catch (\Exception $e) {
Expand All @@ -215,7 +236,7 @@ function ($view) use ($debugbar) {
}
}

if ($this->shouldCollect('log', true)) {
if (!$this->isLumen() && $this->shouldCollect('log', true)) {
try {
if ($this->hasCollector('messages')) {
$logger = new MessagesCollector('log');
Expand Down Expand Up @@ -301,7 +322,7 @@ function ($query, $bindings, $time, $connectionName) use ($db, $queryCollector)
}
}

if ($this->shouldCollect('mail', true)) {
if ($this->shouldCollect('mail', true) && class_exists('Illuminate\Mail\MailServiceProvider')) {
try {
$mailer = $this->app['mailer']->getSwiftMailer();
$this->addCollector(new SwiftMailCollector($mailer));
Expand Down Expand Up @@ -765,6 +786,11 @@ protected function checkVersion($version, $operator = ">=")
return version_compare($this->version, $version, $operator);
}

protected function isLumen()
{
return $this->is_lumen;
}

/**
* @param DebugBar $debugbar
*/
Expand Down
Loading

0 comments on commit 331cb3f

Please sign in to comment.