Skip to content

Commit

Permalink
Move InternalEvents instantiation to plugins array
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdotcom committed Aug 13, 2023
1 parent 60b3bfd commit 9f4007b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Debug/AbstractDebug.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public function onConfig(Event $event)
return;
}
$event['debug'] = $cfg;
$cfg = $this->container['pluginChannel']->getPropagateValues($event->getValues());
$cfg = $this->getPlugin('channel')->getPropagateValues($event->getValues());
unset($cfg['currentSubject'], $cfg['isTarget']);
foreach ($channels as $channel) {
$channel->config->set($cfg);
}
Expand Down Expand Up @@ -302,7 +303,6 @@ private function bootstrap($cfg)
$this->eventManager->addSubscriberInterface($this->container['pluginManager']);

$this->addPlugin($this->container['pluginChannel']);
$this->addPlugin($this->container['pluginConfigEvents']);

if (!$this->parentInstance) {
// we're the root instance
Expand Down
6 changes: 3 additions & 3 deletions src/Debug/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private function publishConfigEvent(array $configs)
Debug::EVENT_CONFIG,
$this->debug,
\array_merge($configs, array(
'currentTarget' => $this->debug,
'currentSubject' => $this->debug,
'isTarget' => true,
))
)->getValues();
Expand All @@ -427,12 +427,12 @@ private function publishConfigEvent(array $configs)
Debug::EVENT_CONFIG,
$this->debug,
\array_merge($configs, array(
'currentTarget' => $this->debug->rootInstance,
'currentSubject' => $this->debug->rootInstance,
'isTarget' => false,
))
)->getValues();
}
unset($configs['currentTarget'], $configs['isTarget']);
unset($configs['currentSubject'], $configs['isTarget']);
return $configs;
}

Expand Down
7 changes: 5 additions & 2 deletions src/Debug/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Brad Kent <[email protected]>
* @license http://opensource.org/licenses/MIT MIT
* @copyright 2014-2022 Brad Kent
* @version v3.0
* @version v3.1
*
* @link http://www.github.com/bkdotcom/PHPDebugConsole
* @link https://developer.mozilla.org/en-US/docs/Web/API/console
Expand Down Expand Up @@ -82,7 +82,7 @@ class Debug extends AbstractDebug
const EVENT_STREAM_WRAP = 'debug.streamWrap';

const META = "\x00meta\x00";
const VERSION = '3.0.4';
const VERSION = '3.1';

protected $cfg = array(
'channelIcon' => 'fa fa-list-ul',
Expand Down 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(
'configEvents' => array(
'class' => 'bdk\Debug\Plugin\ConfigEvents',
),
'internalEvents' => array(
'class' => 'bdk\Debug\Plugin\InternalEvents',
),
Expand Down
2 changes: 2 additions & 0 deletions src/Debug/Plugin/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public function getPropagateValues($cfg)
'channelIcon',
'channelName',
'onBootstrap',
'onLog',
'onOutput',
'route',
)));
foreach ($cfg as $k => $v) {
Expand Down
4 changes: 0 additions & 4 deletions src/Debug/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ public function register(Container $container)
$container['pluginChannel'] = static function () {
return new \bdk\Debug\Plugin\Channel();
};
$container['pluginConfigEvents'] = static function (Container $container) {
$debug = $container['debug'];
return new \bdk\Debug\Plugin\ConfigEvents($debug);
};
$container['pluginHighlight'] = static function () {
return new \bdk\Debug\Plugin\Highlight();
};
Expand Down
12 changes: 6 additions & 6 deletions tests/Debug/ChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ public function testOutput()

public function testCreateChannel()
{
$channelsBack = $this->helper->getProp($this->debug->pluginChannel, 'channels');
$this->helper->setProp($this->debug->pluginChannel, 'channels', array());
$channelsBack = $this->helper->getProp($this->debug->getPlugin('channel'), 'channels');
$this->helper->setProp($this->debug->getPlugin('channel'), 'channels', array());
$tabby = $this->debug->getChannel('tabby', array(
'channelIcon' => 'fa fa-tabby',
'nested' => false,
Expand Down Expand Up @@ -311,7 +311,7 @@ public function testCreateChannel()
'general.foo.bar',
), \array_keys($this->debug->getChannels(true, true)));

$this->helper->setProp($this->debug->pluginChannel, 'channels', $channelsBack);
$this->helper->setProp($this->debug->getPlugin('channel'), 'channels', $channelsBack);
}

public function testGetChannel()
Expand All @@ -327,8 +327,8 @@ public function testGetChannel()
),
));

$channelsBack = $this->helper->getProp($this->debug->pluginChannel, 'channels');
$this->helper->setProp($this->debug->pluginChannel, 'channels', array());
$channelsBack = $this->helper->getProp($this->debug->getPlugin('channel'), 'channels');
$this->helper->setProp($this->debug->getPlugin('channel'), 'channels', array());
$baz = $this->debug->getChannel('baz');
$baz->getChannel('general.foo.bar', array(
'channelIcon' => 'fa fa-asterisk',
Expand All @@ -344,7 +344,7 @@ public function testGetChannel()
$fork = $this->debug->getChannel('utensil.fork');
self::assertSame('fa fa-fork', $fork->getCfg('channelIcon'));

$this->helper->setProp($this->debug->pluginChannel, 'channels', $channelsBack);
$this->helper->setProp($this->debug->getPlugin('channel'), 'channels', $channelsBack);
}

protected function genLog(Debug $clearer = null, $bitmask = null, &$info = array())
Expand Down
16 changes: 9 additions & 7 deletions tests/Debug/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,18 @@ public function testOnCfgOnBootstrap()
/**
* @dataProvider providerOnCfgReplaceSubscriber
*/
public function testOnCfgReplaceSubscriber($name, $event)
public function testOnCfgReplaceSubscriber($cfgName, $eventName)
{
$closure1 = static function () {
};
$this->debug->setCfg($name, $closure1);
$closure2 = static function () {
echo 'you suck!!!' . "\n";
$this->debug->setCfg($cfgName, $closure1);
$closure2 = static function ($event, $name) {
echo 'closure 2 ' . $event->getSubject()->getCfg('channelName', Debug::CONFIG_DEBUG) . ' ' . $name . "\n";
};
$this->debug->setCfg($name, $closure2);
$this->debug->setCfg($cfgName, $closure2);
$closure1isSub = false;
$closure2isSub = false;
foreach ($this->debug->eventManager->getSubscribers($event) as $subInfo) {
foreach ($this->debug->eventManager->getSubscribers($eventName) as $subInfo) {
if ($subInfo['callable'] === $closure1) {
$closure1isSub = true;
}
Expand All @@ -349,7 +349,9 @@ public function testOnCfgReplaceSubscriber($name, $event)
$this->assertFalse($closure1isSub);
$this->assertTrue($closure2isSub);

$this->debug->setCfg($name, null);
$this->debug->setCfg($cfgName, null);

// \bdk\Debug::varDump($eventName, $this->debug->eventManager->getSubscribers($eventName));
}

/*
Expand Down

0 comments on commit 9f4007b

Please sign in to comment.