Skip to content

Commit

Permalink
move Profile, Table, & TableRow to Utility namespace.
Browse files Browse the repository at this point in the history
move ConfigEvents to Plugin namespace
Bootstrap Redaction, MethodGeneral,, & MethodReqRes plugins via plugins array
  • Loading branch information
bkdotcom committed Aug 8, 2023
1 parent 3eefa89 commit 1e7db60
Show file tree
Hide file tree
Showing 29 changed files with 334 additions and 284 deletions.
18 changes: 8 additions & 10 deletions src/Debug/AbstractDebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,23 +300,21 @@ private function bootstrap($cfg)
$this->container->setCfg('onInvoke', array($this->config, 'onContainerInvoke'));
$this->serviceContainer->setCfg('onInvoke', array($this->config, 'onContainerInvoke'));
$this->eventManager->addSubscriberInterface($this->container['pluginManager']);
$this->addPlugin($this->serviceContainer['pluginMethodGeneral']);
$this->addPlugin($this->serviceContainer['pluginMethodReqRes']);
$this->addPlugin($this->container['pluginChannel']);
$this->addPlugin($this->container['configEvents']);
$this->addPlugin($this->serviceContainer['pluginRedaction']);
$this->addPlugin(new \bdk\Debug\Plugin\Route());
$this->eventManager->subscribe(Debug::EVENT_CONFIG, array($this, 'onConfig'));

$this->serviceContainer['errorHandler'];
$this->config->set($cfg);
$this->addPlugin($this->container['pluginChannel']);
$this->addPlugin($this->container['pluginConfigEvents']);
$this->addPlugin(new \bdk\Debug\Plugin\Route(), 'route');

if (!$this->parentInstance) {
// we're the root instance
$this->serviceContainer['errorHandler'];
$this->addPlugins($this->getCfg('plugins', Debug::CONFIG_DEBUG));
$this->data->set('requestId', $this->requestId());
$this->data->set('entryCountInitial', $this->data->get('log/__count__'));
$this->addPlugins($this->getCfg('plugins', Debug::CONFIG_DEBUG));
}

$this->eventManager->subscribe(Debug::EVENT_CONFIG, array($this, 'onConfig'));
$this->config->set($cfg);
$this->eventManager->publish(Debug::EVENT_BOOTSTRAP, $this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Abstraction/Abstracter.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function getAbstraction($val, $method = null, $typeInfo = array(), $hist
return $this->getAbstractionFloat($val, $typeMore);
case self::TYPE_OBJECT:
return $val instanceof \SensitiveParameterValue
? $this->abstractString->getAbstraction(\call_user_func($this->debug->pluginRedaction->getCfg('redactReplace'), 'redacted'))
? $this->abstractString->getAbstraction(\call_user_func($this->debug->getPlugin('redaction')->getCfg('redactReplace'), 'redacted'))
: $this->abstractObject->getAbstraction($val, $method, $hist);
case self::TYPE_RESOURCE:
return new Abstraction($type, array(
Expand Down
11 changes: 10 additions & 1 deletion src/Debug/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,18 @@ class Debug extends AbstractDebug
'methodCount' => array(
'class' => 'bdk\Debug\Plugin\Method\Count',
),
'methodGeneral' => array(
'class' => 'bdk\Debug\Plugin\Method\General',
),
'methodGroup' => array(
'class' => 'bdk\Debug\Plugin\Method\Group',
),
'methodProfile' => array(
'class' => 'bdk\Debug\Plugin\Method\Profile',
),
'methodReqRes' => array(
'class' => 'bdk\Debug\Plugin\Method\ReqRes',
),
'methodTable' => array(
'class' => 'bdk\Debug\Plugin\Method\Table',
),
Expand All @@ -185,14 +191,17 @@ class Debug extends AbstractDebug
'methodTrace' => array(
'class' => 'bdk\Debug\Plugin\Method\Trace',
),
'redaction' => array(
'class' => 'bdk\Debug\Plugin\Redaction',
),
'runtime' => array(
'class' => 'bdk\Debug\Plugin\Runtime',
),
),
'redactKeys' => array( // case-insensitive
'password',
),
// 'redactReplace' // closure (default defined in Plugin/Redaction)
// 'redactReplace' // callable (default defined in Plugin/Redaction)
'route' => 'auto', // 'auto', 'chromeLogger', 'firephp', 'html', 'serverLog', 'script', 'steam', 'text', or RouteInterface,
// if 'auto', will be determined automatically
// if null, no output (unless output plugin added manually)
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Framework/Laravel/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use bdk\Debug\Framework\Laravel\EventsSubscriber;
use bdk\Debug\Framework\Laravel\Middleware;
use bdk\Debug\LogEntry;
use bdk\Debug\Method\TableRow;
use bdk\Debug\Utility\ArrayUtil;
use bdk\Debug\Utility\TableRow;
use bdk\ErrorHandler\Error;
use Illuminate\Contracts\Http\Kernel;
use Illuminate\Database\DatabaseManager;
Expand Down
13 changes: 2 additions & 11 deletions src/Debug/ConfigEvents.php → src/Debug/Plugin/ConfigEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @version v3.0
*/

namespace bdk\Debug;
namespace bdk\Debug\Plugin;

use bdk\Debug;
use bdk\Debug\Utility\FileStreamWrapper;
Expand All @@ -27,16 +27,6 @@ class ConfigEvents implements SubscriberInterface
private $isConfigured = false;
private static $profilingEnabled = false;

/**
* Constructor
*
* @param Debug $debug Debug instance
*/
public function __construct(Debug $debug)
{
$this->debug = $debug;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -67,6 +57,7 @@ public function onBootstrap()
*/
public function onConfig(Event $event)
{
$this->debug = $event->getSubject();
$configs = $event->getValues();
$cfgDebug = $this->onConfigInit($configs);
$valActions = \array_intersect_key(array(
Expand Down
17 changes: 0 additions & 17 deletions src/Debug/Plugin/InternalEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace bdk\Debug\Plugin;

use bdk\Debug;
use bdk\Debug\LogEntry;
use bdk\Debug\Route\Stream;
use bdk\ErrorHandler;
use bdk\ErrorHandler\Error;
Expand Down Expand Up @@ -41,7 +40,6 @@ public function getSubscriptions()
*/
return array(
Debug::EVENT_DUMP_CUSTOM => array('onDumpCustom', -1),
Debug::EVENT_LOG => array('onLog', PHP_INT_MAX),
Debug::EVENT_OUTPUT => array(
array('onOutput', 1),
array('onOutputHeaders', -1),
Expand Down Expand Up @@ -130,21 +128,6 @@ public function onError(Error $error)
$error['inConsole'] = false;
}

/**
* Debug::EVENT_LOG subscriber
*
* @param LogEntry $logEntry LogEntry instance
*
* @return void
*/
public function onLog(LogEntry $logEntry)
{
if ($logEntry->getMeta('redact')) {
$debug = $logEntry->getSubject();
$logEntry['args'] = $debug->redact($logEntry['args']);
}
}

/**
* Debug::EVENT_OUTPUT subscriber
*
Expand Down
8 changes: 4 additions & 4 deletions src/Debug/Plugin/LogReqRes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
class LogReqRes implements SubscriberInterface
{
protected $cfg = array(
'channelName' => 'Request / Response',
'channelOpts' => array(
'channelIcon' => 'fa fa-exchange',
'channelSort' => 10,
Expand All @@ -42,8 +43,8 @@ class LogReqRes implements SubscriberInterface
public function getSubscriptions()
{
return array(
Debug::EVENT_OUTPUT => array('logResponse', PHP_INT_MAX),
Debug::EVENT_BOOTSTRAP => 'onBootstrap',
Debug::EVENT_OUTPUT => array('logResponse', PHP_INT_MAX),
);
}

Expand All @@ -57,6 +58,7 @@ public function getSubscriptions()
public function onBootstrap(Event $event)
{
$this->debug = $event->getSubject();
$this->setChannel();
$collectWas = $this->debug->setCfg('collect', true);
$this->logRequest();
$this->debug->setCfg('collect', $collectWas);
Expand All @@ -72,7 +74,6 @@ public function logRequest()
if ($this->testLogRequest() === false) {
return;
}
$this->setChannel();
$this->debug->log(
'Request',
$this->debug->meta(array(
Expand Down Expand Up @@ -106,7 +107,6 @@ public function logResponse()
if ($this->testLogResponse() === false) {
return;
}
$this->setChannel();
$this->debug->log(
'Response',
$this->debug->meta(array(
Expand Down Expand Up @@ -368,7 +368,7 @@ private function setChannel()
if ($this->debug->parentInstance) {
return;
}
$this->debug = $this->debug->getChannel('Request / Response', $this->cfg['channelOpts']);
$this->debug = $this->debug->getChannel($this->cfg['channelName'], $this->cfg['channelOpts']);
}

/**
Expand Down
37 changes: 36 additions & 1 deletion src/Debug/Plugin/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use bdk\Debug;
use bdk\Debug\AssetProviderInterface;
use bdk\Debug\ConfigurableInterface;
use bdk\Debug\PluginInterface;
use bdk\Debug\Plugin\CustomMethodTrait;
use bdk\Debug\PluginInterface;
use bdk\Debug\Route\RouteInterface;
use bdk\PubSub\Event;
use bdk\PubSub\SubscriberInterface;
Expand Down Expand Up @@ -45,6 +45,8 @@ class Manager implements SubscriberInterface

protected $namedPlugins = array();

private $isBootstrapped = false;

/**
* Constructor
*/
Expand Down Expand Up @@ -147,6 +149,17 @@ public function getPlugin($pluginName)
return $this->namedPlugins[$pluginName];
}

/**
* {@inheritDoc}
*/
public function getSubscriptions()
{
return array(
Debug::EVENT_BOOTSTRAP => 'onBootstrap',
Debug::EVENT_CUSTOM_METHOD => 'onCustomMethod',
);
}

/**
* Test if we already have plugin
*
Expand All @@ -163,6 +176,16 @@ public function hasPlugin($plugin)
return $this->registeredPlugins->contains($plugin);
}

/**
* Debug::EVENT_BOOTSTRAP subscriber
*
* @return void
*/
public function onBootstrap()
{
$this->isBootstrapped = true;
}

/**
* Remove plugin
*
Expand Down Expand Up @@ -231,6 +254,18 @@ private function addSubscriberInterface(SubscriberInterface $plugin)
$this->debug->eventManager
);
}
if (isset($subscriptions[Debug::EVENT_BOOTSTRAP]) && $this->isBootstrapped) {
/*
plugin subscribes to Debug::EVENT_BOOTSTRAP
and we've already bootstrapped
*/
\call_user_func(
array($plugin, $subscriptions[Debug::EVENT_BOOTSTRAP]),
new Event($this->debug),
Debug::EVENT_BOOTSTRAP,
$this->debug->eventManager
);
}
$this->debug->eventManager->addSubscriberInterface($plugin);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Plugin/Method/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use bdk\Debug\Abstraction\Abstracter;
use bdk\Debug\Abstraction\Abstraction;
use bdk\Debug\LogEntry;
use bdk\Debug\Method\Profile as ProfileInstance;
use bdk\Debug\Plugin\CustomMethodTrait;
use bdk\Debug\Utility\Profile as ProfileInstance;
use bdk\PubSub\SubscriberInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Debug/Plugin/Method/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use bdk\Debug;
use bdk\Debug\Abstraction\Abstracter;
use bdk\Debug\LogEntry;
use bdk\Debug\Method\Table as TableProcessor;
use bdk\Debug\Plugin\CustomMethodTrait;
use bdk\Debug\Utility\Table as TableProcessor;
use bdk\PubSub\SubscriberInterface;

/**
Expand Down
37 changes: 35 additions & 2 deletions src/Debug/Plugin/Redaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* @package PHPDebugConsole
* @author Brad Kent <bkfake-github@yahoo.com>
* @license http://opensource.org/licenses/MIT MIT
* @copyright 2014-2022 Brad Kent
* @version v3.0
* @copyright 2014-2023 Brad Kent
* @version v3.1
*/

namespace bdk\Debug\Plugin;
Expand All @@ -16,6 +16,7 @@
use bdk\Debug\AbstractComponent;
use bdk\Debug\Abstraction\Abstracter;
use bdk\Debug\Abstraction\Abstraction;
use bdk\Debug\LogEntry;
use bdk\Debug\Plugin\CustomMethodTrait;
use bdk\PubSub\Event;
use bdk\PubSub\SubscriberInterface;
Expand Down Expand Up @@ -79,6 +80,8 @@ public function getSubscriptions()
return array(
Debug::EVENT_CONFIG => 'onConfig',
Debug::EVENT_CUSTOM_METHOD => 'onCustomMethod',
Debug::EVENT_LOG => array('onLog', PHP_INT_MAX),
Debug::EVENT_PLUGIN_INIT => 'onPluginInit',
);
}

Expand Down Expand Up @@ -109,6 +112,36 @@ public function onConfig(Event $event)
$event['debug'] = \array_merge($event['debug'], $cfg);
}

/**
* Debug::EVENT_LOG subscriber
*
* @param LogEntry $logEntry LogEntry instance
*
* @return void
*/
public function onLog(LogEntry $logEntry)
{
if ($logEntry->getMeta('redact')) {
$logEntry['args'] = $this->redact($logEntry['args']);
}
}

/**
* Debug::EVENT_PLUGIN_INIT subscriber
*
* @param Event $event Debug::EVENT_PLUGIN_INIT Event instance
*
* @return void
*/
public function onPluginInit(Event $event)
{
$debug = $event->getSubject();
$event = new Event($debug, array(
'debug' => $debug->getCfg(null, Debug::CONFIG_DEBUG),
));
$this->onConfig($event);
}

/**
* Redact
*
Expand Down
Loading

0 comments on commit 1e7db60

Please sign in to comment.