Skip to content

Commit

Permalink
Move channel plugin instantiation to plugins config
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Aug 13, 2023
1 parent 9f4007b commit 25c44cc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/Debug/AbstractDebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'];
Expand Down
3 changes: 3 additions & 0 deletions src/Debug/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
Expand Down
34 changes: 18 additions & 16 deletions src/Debug/Plugin/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/Debug/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
6 changes: 3 additions & 3 deletions tests/Debug/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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',
Expand Down

0 comments on commit 25c44cc

Please sign in to comment.