Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions plugins/system/debug/debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use DebugBar\DataCollector\RequestDataCollector;
use DebugBar\DebugBar;
use DebugBar\OpenHandler;
use Joomla\Application\ApplicationEvents;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Document\HtmlDocument;
use Joomla\CMS\Log\Log;
Expand All @@ -25,6 +26,7 @@
use Joomla\Database\DatabaseDriver;
use Joomla\Database\Event\ConnectionEvent;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Plugin\System\Debug\DataCollector\InfoCollector;
use Joomla\Plugin\System\Debug\DataCollector\LanguageErrorsCollector;
use Joomla\Plugin\System\Debug\DataCollector\LanguageFilesCollector;
Expand All @@ -40,7 +42,7 @@
*
* @since 1.5
*/
class PlgSystemDebug extends CMSPlugin
class PlgSystemDebug extends CMSPlugin implements SubscriberInterface
{
/**
* True if debug lang is on.
Expand Down Expand Up @@ -136,6 +138,25 @@ class PlgSystemDebug extends CMSPlugin
*/
protected $showLogs = false;

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onBeforeCompileHead' => 'onBeforeCompileHead',
'onAjaxDebug' => 'onAjaxDebug',
'onBeforeRespond' => 'onBeforeRespond',
'onAfterRespond' => 'onAfterRespond',
ApplicationEvents::AFTER_RESPOND => 'onAfterRespond',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't this two lines identical?

Copy link
Member Author

@Fedik Fedik Apr 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, and that the issue, should be somehow fixed in J5, I guess

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application class trigger diferent AfterRespond event for normal request, and for redirect (that usualy happen after POST)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'onAfterDisconnect' => 'onAfterDisconnect',
];
}

/**
* Constructor.
*
Expand Down Expand Up @@ -245,7 +266,7 @@ public function onBeforeCompileHead()
public function onAfterRespond()
{
// Do not render if debugging or language debug is not enabled.
if (!JDEBUG && !$this->debugLang || $this->isAjax || !($this->app->getDocument() instanceof HtmlDocument))
if (!JDEBUG && !$this->debugLang || $this->isAjax)
{
return;
}
Expand Down Expand Up @@ -349,32 +370,34 @@ public function onAfterRespond()
/**
* AJAX handler
*
* @return string
* @param Joomla\Event\Event $event
*
* @return void
*
* @since 4.0.0
*/
public function onAjaxDebug()
public function onAjaxDebug($event)
{
// Do not render if debugging or language debug is not enabled.
if (!JDEBUG && !$this->debugLang)
{
return '';
return;
}

// User has to be authorised to see the debug information.
if (!$this->isAuthorisedDisplayDebug() || !Session::checkToken('request'))
{
return '';
return;
}

switch ($this->app->input->get('action'))
{
case 'openhandler':
$result = $event['result'] ?: [];
$handler = new OpenHandler($this->debugBar);

return $handler->handle($this->app->input->request->getArray(), false, false);
default:
return '';
$result[] = $handler->handle($this->app->input->request->getArray(), false, false);
$event['result'] = $result;
}
}

Expand Down