Skip to content

Commit

Permalink
Issues #3 #4 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmerlin committed Jan 18, 2023
1 parent fd3b94d commit e9cfdc0
Show file tree
Hide file tree
Showing 29 changed files with 6,180 additions and 25 deletions.
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,37 @@ Once installed, the following components need to be registered by adding:
* `\Dot\DebugBar\ConfigProvider::class,` to `config/config.php` (preferably at the beginning of the section where the `DotKernel packages` are loaded)
* `\Dot\DebugBar\Extension\DebugBarExtension::class` to `config/autoload/templates.global.php` (inside the array founder under the key `twig` => `extensions`)

Locate the library's assets directory `vendor/maximebf/debugbar/src/DebugBar/Resources` and copy its contents to your application under `public/debugbar` directory.
Locate the library's assets directory, called `assets` and copy **its contents** to your application under `public/debugbar` directory.

Locate the library's config file `vendor/dotkernel/dot-debugbar/config/debugbar.local.php` and make a copy of it inside your application as:
* `config/autoload/debugbar.local.php`
Locate the library's config file `config/debugbar.local.php.dist` and clone it inside your application as:
* `config/autoload/debugbar.local.php.dist`
* `config/autoload/debugbar.local.php`

By default, the debug bar is enabled only on the local environment, by whitelisting `127.0.0.1` in the config file, inside the array located under the `ipWhitelist` key.
If you need to enable it on other environments as well, just whitelist your public IP address.
By default, dot-debugbar is enabled only on the local environment, by whitelisting `127.0.0.1` in the config file, inside the array located under the `ipv4Whitelist` key.
If you need to enable it on other environments as well, just whitelist your public IPV4 address.
It can also be enabled globally, by whitelisting the string `*`.
Finally, if you want to keep the whitelists but disable dot-debugbar, you can set `enabled` to **false**.

Inside the config file, you will find additional configurations under the `javascript_renderer` key.
For more configuration values, follow the link in the related comment block.


At this step, the debug bar is not displayed yet. In order to display it, you need to call the following Twig functions from your base layout:
At this step, dot-debugbar is not displayed yet. In order to display it, you need to call the following Twig functions from your base layout:
* `{{ debugBarCss()|raw }}` (needs to be placed in the head section of the layout, where the CSS files are included)
* `{{ debugBarJs()|raw }}` (needs to be placed in the footer of the layout, where the JS files are included)

If you plan to enable dot-debugbar on production, make sure you clear the relevant cache items by deleting:
* the config cache file: `data/cache/config-cache.php`
* Twig cache directory: `data/cache/twig`

Additionally, you can check if the debug bar is enabled for your session by calling `debugBarEnabled()` inside a template.
This feature can be useful if you need to add custom logic for when the debug bar is enabled.
Additionally, you can check if dot-debugbar is enabled for your session by calling `debugBarEnabled()` inside a template.
This feature can be useful if you need to add custom logic for when dot-debugbar is enabled.


## Usage
Other than the data being automatically collected during a session, the debug bar can also be used to log messages, measure durations, debug database queries and more...
Other than the data being automatically collected during a session, dot-debugbar can also be used to log messages, measure durations, debug database queries and more...

When you need an instance of the debug bar, locate an instance of it in your application's container using:
When you need an instance of DebugBar, locate an instance of it in your application's container using:
```php
$debugBar = $container->get(\Dot\DebugBar\DebugBar::class);
```
Expand All @@ -73,6 +74,8 @@ Results will show up in the debug bar under the `Messages` tab.

Log messages (can be of any type):
```php
$this->debugBar->addMessage(1);
$this->debugBar->addMessage(true);
$this->debugBar->addMessage('foo');
$this->debugBar->addMessage(['foo']);
$this->debugBar->addMessage(new \stdClass());
Expand All @@ -87,16 +90,24 @@ $this->debugBar->addMessage('some warning', 'warning');
$this->debugBar->addMessage('custom message', 'custom');
```

Also, clicking on a label will toggle the visibility of all messages with that specific label.
Also, clicking on a label (found on the bottom right of the debugbar) will toggle the visibility of all messages with that specific label.


### Measure durations
Results will show up in the debug bar under the `Timeline` tab.

In order to measure how long does it take for a piece of code to execute, do the following:
```php
$this->debugBar->measure('long operation', function () {
// your code here
});
```

OR

```php
$this->debugBar->startTimer('long operation', 'measuring long operation');
// do stuff that needs to be measured
// your code here
$this->debugBar->stopTimer('long operation');
```

Expand All @@ -112,3 +123,8 @@ $this->debugBar->stackData();

The method needs to be called after all database operations have finished AND before emitting the redirect response.
In this case, next to the `Memory usage` widget you'll see a dropdown that allows you to select between the previous page load (with the redirect) and the current one.

### Debug Exceptions
Results will show up in the debug bar under the `Exceptions` tab.

By registering `Dot\DebugBar\Middleware\DebugBarMiddleware`, dot-debugbar is ready to capture Exceptions.
Loading

0 comments on commit e9cfdc0

Please sign in to comment.