Skip to content

Commit f609aaa

Browse files
committed
IMplements addBootLoaders and setBootLoaders methods
1 parent a4cb777 commit f609aaa

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@
3333
<html outputDirectory="test-coverage-report/" />
3434
</report>
3535
</coverage>
36+
37+
<logging>
38+
<log type="coverage-clover" target="coverage/clover.xml"/>
39+
</logging>
40+
3641
</phpunit>

src/Kernel.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Kernel implements KernelInterface
3434
*/
3535
public function __construct(
3636
private readonly array $applicationPluginCollection,
37-
private readonly iterable $pluginBootLoaderCollection,
37+
private array $pluginBootLoaderCollection,
3838
private readonly Container $container
3939
) {
4040
$this->isStarted = false;
@@ -43,6 +43,28 @@ public function __construct(
4343
$this->plugins = [];
4444
}
4545

46+
public function addBootLoader(PluginBootLoaderInterface $bootLoader): self
47+
{
48+
if ($this->isStarted) {
49+
throw new \LogicException('Bootloaders must be installed before starting the kernel.');
50+
}
51+
52+
$this->pluginBootLoaderCollection[] = $bootLoader;
53+
54+
return $this;
55+
}
56+
57+
public function setBootLoaders(iterable $bootLoaders): self
58+
{
59+
$this->pluginBootLoaderCollection = [];
60+
61+
foreach ($bootLoaders as $loader) {
62+
$this->addBootLoader($loader);
63+
}
64+
65+
return $this;
66+
}
67+
4668
/**
4769
* {@inheritDoc}
4870
*/

src/KernelInterface.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Micro\Framework\Kernel;
1313

1414
use Micro\Component\DependencyInjection\Container;
15+
use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface;
1516

1617
/**
1718
* The kernel is needed for plugin management. A plugin can be any class object.
@@ -25,6 +26,18 @@ interface KernelInterface
2526
*/
2627
public function container(): Container;
2728

29+
/**
30+
* @throws \RuntimeException
31+
*/
32+
public function addBootLoader(PluginBootLoaderInterface $bootLoader): self;
33+
34+
/**
35+
* @param iterable<PluginBootLoaderInterface> $bootLoaders
36+
*
37+
* @throws \RuntimeException
38+
*/
39+
public function setBootLoaders(iterable $bootLoaders): self;
40+
2841
/**
2942
* Run application.
3043
*

tests/Unit/KernelTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,22 @@ protected function setUp(): void
4646

4747
$this->kernel = new Kernel(
4848
$plugins,
49-
$bootLoaders,
49+
[],
5050
$this->container,
5151
);
5252

53+
$this->kernel->setBootLoaders($bootLoaders);
54+
$this->kernel->addBootLoader($this->createMock(PluginBootLoaderInterface::class));
55+
5356
$this->kernel->run();
5457
}
5558

59+
public function testExceptionWhenTryBootloaderInstallAfterKernelRun()
60+
{
61+
$this->expectException(\LogicException::class);
62+
$this->kernel->addBootLoader($this->createMock(PluginBootLoaderInterface::class));
63+
}
64+
5665
public function testKernelPlugins()
5766
{
5867
foreach ($this->kernel->plugins(\stdClass::class) as $plugin) {

0 commit comments

Comments
 (0)