Skip to content

Commit

Permalink
Add helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Sep 5, 2014
1 parent c092d6a commit 5caa921
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 7 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for Laravel Debugbar

## 1.7.3 (2014-09-..)

- Add helper functions (debug(), add/start/stop_measure() and measure()

## 1.7.2 (2014-09-04)

- Fix 4.0 compatibility (problem with Controller namespace)
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
"autoload": {
"psr-4": {
"Barryvdh\\Debugbar\\": "src/"
}
},
"files": [
"src/helpers.php"
]
},
"extra": {
"branch-alias": {
Expand Down
22 changes: 17 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Require this package in your composer.json and run composer update (or run `comp
After updating composer, add the ServiceProvider to the providers array in app/config/app.php

'Barryvdh\Debugbar\ServiceProvider',

If you want to use the facade to log messages, add this to your facades in app.php:

'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.

Expand All @@ -55,11 +59,7 @@ You can also only display the js of css vendors, by setting it to 'js' or 'css'.

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)`)

If you want to use the facade to log messages, add this to your facades in app.php:

'Debugbar' => 'Barryvdh\Debugbar\Facade',

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

Debugbar::info($object);
Debugbar::error("Error!");
Expand All @@ -82,6 +82,18 @@ Or log exceptions:
} catch (Exception $e) {
Debugbar::addException($e);
}

There are also helper functions available for the most common calls:

// All arguments will be dumped as a debug message
debug($var1, $someString, $intValue, $object);

start_measure('render','Time for rendering');
stop_measure('render');
add_measure('now', LARAVEL_START, microtime(true));
measure('My long operation', function() {
//Do something..
});

If you want you can add your own DataCollectors, through the Container or the Facade:

Expand Down
2 changes: 1 addition & 1 deletion src/LaravelDebugBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function addMeasure($label, $start, $end)
* Utility function to measure the execution of a Closure
*
* @param string $label
* @param \Closure|callable $closure
* @param \Closure $closure
*/
public function measure($label, \Closure $closure)
{
Expand Down
65 changes: 65 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

if ( ! function_exists('debug')) {
/**
* Adds one or more messages to the MessagesCollector
*
* @param mixed ...$value
* @return string
*/
function debug($value)
{
$debugbar = app('debugbar');
foreach(func_get_args() as $value){
$debugbar->addMessage($value, 'debug');
}
}
}

if ( ! function_exists('start_measure')) {
/**
* Starts a measure
*
* @param string $name Internal name, used to stop the measure
* @param string $label Public name
*/
function start_measure($name, $label = null) {
app('debugbar')->startMeasure($name, $label);
}
}

if ( ! function_exists('stop_measure')) {
/**
* Stop a measure
*
* @param string $name Internal name, used to stop the measure
*/
function stop_measure($name) {
app('debugbar')->stopMeasure($name);
}
}

if ( ! function_exists('add_measure')) {
/**
* Adds a measure
*
* @param string $label
* @param float $start
* @param float $end
*/
function add_measure($label, $start, $end) {
app('debugbar')->addMeasure($label, $start, $end);
}
}

if ( ! function_exists('measure')) {
/**
* Utility function to measure the execution of a Closure
*
* @param string $label
* @param \Closure $closure
*/
function measure($label, \Closure $closure) {
app('debugbar')->measure($label, $closure);
}
}

0 comments on commit 5caa921

Please sign in to comment.