From 25c44ccd09cc003b45175145a461e5de5b3ef70d Mon Sep 17 00:00:00 2001 From: Brad Kent Date: Sun, 13 Aug 2023 13:18:42 -0500 Subject: [PATCH] Move channel plugin instantiation to plugins config --- src/Debug/AbstractDebug.php | 4 +--- src/Debug/Debug.php | 3 +++ src/Debug/Plugin/Channel.php | 34 ++++++++++++++++++---------------- src/Debug/ServiceProvider.php | 3 --- tests/Debug/ChannelTest.php | 6 +++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Debug/AbstractDebug.php b/src/Debug/AbstractDebug.php index 409a55b1..1d3b5412 100644 --- a/src/Debug/AbstractDebug.php +++ b/src/Debug/AbstractDebug.php @@ -193,7 +193,7 @@ public function onConfig(Event $event) return; } $event['debug'] = $cfg; - $cfg = $this->getPlugin('channel')->getPropagateValues($event->getValues()); + $cfg = $this->rootInstance->getPlugin('channel')->getPropagateValues($event->getValues()); unset($cfg['currentSubject'], $cfg['isTarget']); foreach ($channels as $channel) { $channel->config->set($cfg); @@ -302,8 +302,6 @@ private function bootstrap($cfg) $this->serviceContainer->setCfg('onInvoke', array($this->config, 'onContainerInvoke')); $this->eventManager->addSubscriberInterface($this->container['pluginManager']); - $this->addPlugin($this->container['pluginChannel']); - if (!$this->parentInstance) { // we're the root instance $this->serviceContainer['errorHandler']; diff --git a/src/Debug/Debug.php b/src/Debug/Debug.php index ff4ce012..58424003 100644 --- a/src/Debug/Debug.php +++ b/src/Debug/Debug.php @@ -143,6 +143,9 @@ class Debug extends AbstractDebug 'output' => false, // output the log? 'outputHeaders' => true, // ie, ChromeLogger and/or firePHP headers 'plugins' => array( + 'channel' => array( + 'class' => 'bdk\Debug\Plugin\Channel', + ), 'configEvents' => array( 'class' => 'bdk\Debug\Plugin\ConfigEvents', ), diff --git a/src/Debug/Plugin/Channel.php b/src/Debug/Plugin/Channel.php index 432626a1..04f4f4cc 100644 --- a/src/Debug/Plugin/Channel.php +++ b/src/Debug/Plugin/Channel.php @@ -56,12 +56,13 @@ public function getChannel($name, $config = array()) ? $this->debug->rootInstance->getChannel($names, $config) : $this->debug->rootInstance; } - if (!isset($this->channels[$name])) { - $this->channels[$name] = $this->createChannel($name, $names + $curChannelName = $this->debug->getCfg('channelName', Debug::CONFIG_DEBUG); + if (!isset($this->channels[$curChannelName][$name])) { + $this->channels[$curChannelName][$name] = $this->createChannel($name, $names ? array() : $config); } - $channel = $this->channels[$name]; + $channel = $this->channels[$curChannelName][$name]; if ($names) { $channel = $channel->getChannel($names, $config); } @@ -84,28 +85,29 @@ public function getChannel($name, $config = array()) */ public function getChannels($allDescendants = false, $inclTop = false) { - $channels = $this->channels; + $curChannelName = $this->debug->getCfg('channelName', Debug::CONFIG_DEBUG); + $channels = isset($this->channels[$curChannelName]) + ? $this->channels[$curChannelName] + : array(); if ($allDescendants) { - $channels = array(); - foreach ($this->channels as $channel) { + $debug = $this->debug; + $channelsNew = array(); + foreach ($channels as $channel) { $channelName = $channel->getCfg('channelName', Debug::CONFIG_DEBUG); - $channels = \array_merge( - $channels, + $channelsNew = \array_merge( + $channelsNew, array( $channelName => $channel, ), $channel->getChannels(true) ); } + $channels = $channelsNew; + $this->debug = $debug; } - if ($inclTop) { - return $channels; - } - if ($this->debug === $this->debug->rootInstance) { - $channelsTop = $this->getChannelsTop(); - $channels = \array_diff_key($channels, $channelsTop); - } - return $channels; + return $inclTop === false && $this->debug === $this->debug->rootInstance + ? \array_diff_key($channels, $this->getChannelsTop()) + : $channels; } /** diff --git a/src/Debug/ServiceProvider.php b/src/Debug/ServiceProvider.php index 07443119..80982b8d 100644 --- a/src/Debug/ServiceProvider.php +++ b/src/Debug/ServiceProvider.php @@ -118,9 +118,6 @@ public function register(Container $container) $container['phpDoc'] = static function () { return new \bdk\Debug\Utility\PhpDoc(); }; - $container['pluginChannel'] = static function () { - return new \bdk\Debug\Plugin\Channel(); - }; $container['pluginHighlight'] = static function () { return new \bdk\Debug\Plugin\Highlight(); }; diff --git a/tests/Debug/ChannelTest.php b/tests/Debug/ChannelTest.php index 95873795..073a838c 100644 --- a/tests/Debug/ChannelTest.php +++ b/tests/Debug/ChannelTest.php @@ -287,7 +287,7 @@ public function testCreateChannel() self::assertSame('tabby', $tabby->getCfg('channelName')); - // $this->helper->stderr($this->debug->getChannels()); + // $this->debug->varDump($this->debug->getChannels()); self::assertSame(array( 'foo', ), \array_keys($this->debug->getChannels())); @@ -298,13 +298,13 @@ public function testCreateChannel() 'general.foo.bar', ), \array_keys($this->debug->getChannels(true))); - // $this->helper->stderr($this->debug->getChannels(false, true)); + // $this->debug->varDump($this->debug->getChannels(false, true)); self::assertSame(array( 'tabby', 'foo', ), \array_keys($this->debug->getChannels(false, true))); - // $this->helper->stderr($this->debug->getChannels(true, true)); + // $this->debug->varDump($this->debug->getChannels(true, true)); self::assertSame(array( 'tabby', 'general.foo',