Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rainlab/debugbar-plugin
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.2.0
Choose a base ref
...
head repository: rainlab/debugbar-plugin
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
128 changes: 111 additions & 17 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -3,11 +3,21 @@
use App;
use Event;
use Config;
use Cms\Classes\Page;
use Cms\Classes\Layout;
use Cms\Classes\Controller as CmsController;
use Backend\Models\UserRole;
use System\Classes\PluginBase;
use Backend\Classes\Controller as BackendController;
use System\Classes\CombineAssets;
use System\Classes\PluginBase;
use RainLab\Debugbar\DataCollectors\OctoberBackendCollector;
use RainLab\Debugbar\DataCollectors\OctoberCmsCollector;
use RainLab\Debugbar\DataCollectors\OctoberComponentsCollector;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Contracts\Http\Kernel as HttpKernelContract;
use Twig\Extension\ProfilerExtension;
use Twig\Profiler\Profile;

/**
* Plugin Information File
*/
@@ -20,17 +30,16 @@ class Plugin extends PluginBase

/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'rainlab.debugbar::lang.plugin.name',
'name' => 'rainlab.debugbar::lang.plugin.name',
'description' => 'rainlab.debugbar::lang.plugin.description',
'author' => 'RainLab',
'icon' => 'icon-bug',
'homepage' => 'https://github.com/rainlab/debugbar-plugin'
'author' => 'RainLab',
'icon' => 'icon-bug',
'homepage' => 'https://github.com/rainlab/debugbar-plugin'
];
}

@@ -39,24 +48,42 @@ public function pluginDetails()
*/
public function boot()
{
// Configure the debugbar
Config::set('debugbar', Config::get('rainlab.debugbar::config'));
// Transfer config to debugbar namespace
Config::set('debugbar', Config::get('rainlab.debugbar::config', []));

// Disabled by config, halt
if (Config::get('debugbar.enabled') === false) {
return;
}

// Service provider
// Register service provider
App::register(\RainLab\Debugbar\Classes\ServiceProvider::class);

// Register alias
$alias = AliasLoader::getInstance();
$alias->alias('Debugbar', \Barryvdh\Debugbar\Facade::class);
$alias->alias('Debugbar', \Barryvdh\Debugbar\Facades\Debugbar::class);

// Register middleware
if (Config::get('app.debugAjax', false)) {
if (Config::get('app.debug_ajax', Config::get('app.debugAjax', false))) {
$this->app[HttpKernelContract::class]->pushMiddleware(\RainLab\Debugbar\Middleware\InterpretsAjaxExceptions::class);
}

// Custom debugbar collectors and extensions
$this->registerResourceInjection();

$this->registerTwigExtensions();
if (App::runningInBackend()) {
$this->addBackendCollectors();
}
else {
// Only Twig 2 is supported at this stage
if (class_exists('\Twig_Extension')) {
$this->registerCmsTwigExtensions();
}

$this->addFrontendCollectors();
}

$this->addGlobalCollectors();
}

/**
@@ -73,17 +100,84 @@ public function register()
}

/**
* registerTwigExtensions
* addGlobalCollectors adds globally available collectors
*/
public function addGlobalCollectors()
{
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugBar */
$debugBar = $this->app->make(\Barryvdh\Debugbar\LaravelDebugbar::class);
$modelsCollector = $this->app->make(\RainLab\Debugbar\DataCollectors\OctoberModelsCollector::class);
$debugBar->addCollector($modelsCollector);
}

/**
* addFrontendCollectors used by the frontend only
*/
public function addFrontendCollectors()
{
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugBar */
$debugBar = $this->app->make(\Barryvdh\Debugbar\LaravelDebugbar::class);

Event::listen('cms.page.beforeDisplay', function(CmsController $controller, $url, ?Page $page) use ($debugBar) {
if ($page) {
$collector = new OctoberCmsCollector($controller, $url, $page);
if (!$debugBar->hasCollector($collector->getName())) {
$debugBar->addCollector($collector);
}
}
});

Event::listen('cms.page.initComponents', function(CmsController $controller, ?Page $page, ?Layout $layout) use ($debugBar) {
if ($page) {
$collector = new OctoberComponentsCollector($controller, $page, $layout);
if (!$debugBar->hasCollector($collector->getName())) {
$debugBar->addCollector($collector);
}
}
});
}

/**
* addBackendCollectors used by the backend only
*/
public function addBackendCollectors()
{
/** @var \Barryvdh\Debugbar\LaravelDebugbar $debugBar */
$debugBar = $this->app->make(\Barryvdh\Debugbar\LaravelDebugbar::class);

Event::listen('backend.page.beforeDisplay', function (BackendController $controller, $action, array $params) use ($debugBar) {
$collector = new OctoberBackendCollector($controller, $action, $params);
if (!$debugBar->hasCollector($collector->getName())) {
$debugBar->addCollector($collector);
}
});
}

/**
* registerCmsTwigExtensions in the CMS Twig environment
*/
protected function registerTwigExtensions()
protected function registerCmsTwigExtensions()
{
Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) {
$profile = new Profile;
$debugBar = $this->app->make(\Barryvdh\Debugbar\LaravelDebugbar::class);

Event::listen('cms.page.beforeDisplay', function ($controller, $url, $page) use ($profile, $debugBar) {
$twig = $controller->getTwig();
if (!$twig->hasExtension(\Barryvdh\Debugbar\Twig\Extension\Debug::class)) {
$twig->addExtension(new \Barryvdh\Debugbar\Twig\Extension\Debug($this->app));
$twig->addExtension(new \Barryvdh\Debugbar\Twig\Extension\Stopwatch($this->app));
}

if (!$twig->hasExtension(ProfilerExtension::class)) {
$twig->addExtension(new ProfilerExtension($profile));
}
});

if (class_exists(\DebugBar\Bridge\NamespacedTwigProfileCollector::class)) {
$debugBar->addCollector(new \DebugBar\Bridge\NamespacedTwigProfileCollector($profile));
} else {
$debugBar->addCollector(new \DebugBar\Bridge\TwigProfileCollector($profile));
}
}

/**
@@ -99,9 +193,9 @@ protected function registerResourceInjection()
}
};

Event::listen('backend.page.beforeDisplay', $addResources, PHP_INT_MAX);
Event::listen('backend.page.beforeDisplay', $addResources, 500);

Event::listen('cms.page.beforeDisplay', $addResources, PHP_INT_MAX);
Event::listen('cms.page.beforeDisplay', $addResources, 500);
}

/**
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# Debugbar Plugin

Easily see what's going on under the hood of your October application.
Easily see what's going on under the hood of your October CMS application.

# Installation

To install from the [Marketplace](https://octobercms.com/plugin/rainlab-debugbar), click on the "Add to Project" button and then select the project you wish to add it to and pay for the plugin. Once the plugin has been added to the project, go to the backend and check for updates to pull in the plugin.
To install with Composer, run from your project root

To install from the backend, go to **Settings -> Updates & Plugins -> Install Plugins** and then search for `RainLab.DebugBar`.
```sh
composer require rainlab/debugbar-plugin
```

To install from [the repository](https://github.com/rainlab/debugbar-plugin), clone it into **plugins/rainlab/debugbar** and then run `composer update` from your project root in order to pull in the dependencies.
# Usage

To install it with Composer, run `composer require rainlab/debugbar-plugin` from your project root.
Set `debug` to `true` in `config/app.php` and the debugbar should appear on your site to all authenticated backend users with the `rainlab.debugbar.access_debugbar` permission.

### Usage

Set `debug` to `true` in `config/app.php`, and the debugbar should appear on your site to all authenticated backend users with the `rainlab.debugbar.access_debugbar` permission. If you would like to make the debugbar accessible to all users regardless of authentication & permissions, then set `allow_public_access` to `true` in `config/rainlab/debugbar/config.php`.
If you would like to make the debugbar accessible to all users regardless of authentication and permissions, then set `allow_public_access` to `true` in the configuration (see below).

See [barryvdh/laravel-debugbar](https://github.com/barryvdh/laravel-debugbar) for more usage instructions and documentation.

To include exceptions in the response header of ajax calls set `debugAjax` to `true` in `config/app.php`.
# Configuration

All configuration for the plugin is found in the **plugins/rainlab/debugbar** directory. To override any of these settings, create an override file called **config/rainlab/debugbar/config.php** in your local system.

To include exceptions in the response header of ajax calls set `debug_ajax` to `true` in **config/app.php**.

Events are not captured by default since it can slow down the front-end when many events are fired, you may enable it with the `collectors.events` setting.
Loading