Skip to content

Commit

Permalink
Merge pull request #4 from Micro-PHP/release-1.2
Browse files Browse the repository at this point in the history
v1.2 release
  • Loading branch information
Asisyas authored Nov 25, 2022
2 parents 9899b4d + de63db2 commit 44049f8
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 108 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "micro/kernel-app",
"description": "Micro Framework: App Kernel component",
"type": "library",
"version": "0.1",
"version": "1.2",
"license": "MIT",
"autoload": {
"psr-4": {
Expand All @@ -16,6 +16,10 @@
}
],
"require": {
"micro/kernel": "^0.1"
"micro/kernel": "^1",
"micro/deprecation-supports": "^1",
"micro/plugin-event-emitter": "^1",
"micro/kernel-boot-dependency": "^1",
"micro/kernel-boot-configuration": "^1"
}
}
58 changes: 44 additions & 14 deletions src/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
namespace Micro\Kernel\App;

use Micro\Component\DependencyInjection\Container;
use Micro\Framework\Kernel\Boot\ConfigurationProviderBootLoader;
use Micro\Framework\Kernel\Boot\DependencyProviderBootLoader;
use Micro\Framework\Kernel\Configuration\ApplicationConfigurationInterface;
use Micro\Framework\Kernel\Container\ApplicationContainerFactoryInterface;
use Micro\Framework\Kernel\Container\Impl\ApplicationContainerFactory;
use Micro\Framework\Kernel\KernelBuilder;
use Micro\Framework\Kernel\KernelInterface;
use Micro\Framework\Kernel\Plugin\BootLoader\ProvideDependenciesBootLoader;
use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface;
use Micro\Kernel\App\Business\KernelActionProcessorInterface;
use Micro\Kernel\App\Business\KernelRunActionProcessor;
use Micro\Kernel\App\Business\KernelTerminateActionProcessor;
use Micro\Plugin\EventEmitter\EventEmitterPlugin;
use Psr\Container\ContainerInterface;

class AppKernel implements AppKernelInterface
{
Expand All @@ -21,19 +25,24 @@ class AppKernel implements AppKernelInterface
private KernelInterface $kernel;

/**
* @var Container|null
* @var ContainerInterface|null
*/
private ?Container $container;
private ?ContainerInterface $container;

/**
* @param ApplicationConfigurationInterface $configuration
* @param array $plugins
* @param string $environment
* @var PluginBootLoaderInterface[]
*/
private iterable $additionalBootLoaders = [];

/**
* @param ApplicationConfigurationInterface|array $configuration
* @param array $plugins
* @param string $environment
*/
public function __construct(
private ApplicationConfigurationInterface $configuration,
private array $plugins,
private string $environment = 'dev'
private ApplicationConfigurationInterface|array $configuration = [],
private array $plugins = [],
private readonly string $environment = 'dev'
)
{
$this->container = $this->createApplicationContainerFactory()->create();
Expand Down Expand Up @@ -92,17 +101,33 @@ public function isDevMode(): bool
return $this->environment() === 'dev';
}

/**
* @param PluginBootLoaderInterface $pluginBootLoader
*
* @return $this
*/
public function addBootLoader(PluginBootLoaderInterface $pluginBootLoader): self
{
$this->additionalBootLoaders[] = $pluginBootLoader;

return $this;
}

/**
* @return KernelInterface
*/
protected function createKernel(): KernelInterface
{
$kernel = $this
->createKernelBuilder()
->setApplicationConfiguration($this->configuration)
->setBootLoaders($this->createBootLoaderCollection())
->addBootLoaders($this->createBootLoaderCollection())
->setContainer($this->container)
->setApplicationPlugins($this->plugins)
->setApplicationPlugins(
[
EventEmitterPlugin::class,
...$this->plugins
]
)
->build();

$this->container = null;
Expand Down Expand Up @@ -135,12 +160,17 @@ protected function createTerminateActionProcessor(): KernelActionProcessorInterf
}

/**
* @return ProvideDependenciesBootLoader[]
* @return PluginBootLoaderInterface[]
*/
protected function createBootLoaderCollection(): array
{
$bl = $this->additionalBootLoaders;
$this->additionalBootLoaders = [];

return [
new ProvideDependenciesBootLoader($this->container),
new DependencyProviderBootLoader($this->container),
new ConfigurationProviderBootLoader($this->configuration),
...$bl
];
}

Expand Down
8 changes: 8 additions & 0 deletions src/AppKernelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Micro\Kernel\App;

use Micro\Framework\Kernel\KernelInterface;
use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface;

interface AppKernelInterface extends KernelInterface
{
Expand All @@ -15,4 +16,11 @@ public function environment(): string;
* @return bool
*/
public function isDevMode(): bool;

/**
* @param PluginBootLoaderInterface $pluginBootLoader
*
* @return $this
*/
public function addBootLoader(PluginBootLoaderInterface $pluginBootLoader): self;
}
13 changes: 0 additions & 13 deletions src/Business/ApplicationListenerProviderPluginInterface.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Business/KernelRunActionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,18 @@

namespace Micro\Kernel\App\Business;

use Micro\Component\DependencyInjection\Container;
use Micro\Component\EventEmitter\ListenerProviderInterface;
use Micro\Kernel\App\Business\Processor\AppCreateEventRunSuccess;
use Micro\Kernel\App\Business\Processor\PluginEventsListenerRegistration;
use Micro\Kernel\App\Business\Processor\ProvideKernelProcessor;
use Micro\Plugin\EventEmitter\EventsFacadeInterface;

class KernelRunActionProcessor extends AbstractActionProcessor
{
/**
* @param Container $container
*/
public function __construct(private Container $container)
{
}

/**
* {@inheritDoc}
*/
protected function createActionProcessorCollection(): array
{
return [
$this->createProvideKernelProcessor(),
$this->createPluginEventsListenerRegistration(),
$this->createAppCreateEventRunSuccess(),
];
}
Expand All @@ -38,16 +26,6 @@ protected function createAppCreateEventRunSuccess(): KernelActionProcessorInterf
return new AppCreateEventRunSuccess();
}

/**
* @return KernelActionProcessorInterface
*/
protected function createPluginEventsListenerRegistration(): KernelActionProcessorInterface
{
$listenerProvider = $this->container->get(EventsFacadeInterface::class);

return new PluginEventsListenerRegistration($listenerProvider);
}

/**
* @return KernelActionProcessorInterface
*/
Expand Down
54 changes: 0 additions & 54 deletions src/Business/Processor/PluginEventsListenerRegistration.php

This file was deleted.

8 changes: 5 additions & 3 deletions src/Business/Processor/ProvideKernelProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Micro\Kernel\App\Business\Processor;

use Micro\Framework\Kernel\KernelInterface;
use Micro\Kernel\App\AppKernelInterface;
use Micro\Kernel\App\Business\KernelActionProcessorInterface;

Expand All @@ -13,8 +14,9 @@ class ProvideKernelProcessor implements KernelActionProcessorInterface
*/
public function process(AppKernelInterface $appKernel): void
{
$appKernel->container()->register(AppKernelInterface::class, function () use ($appKernel) {
return $appKernel;
});
$callback = fn() => $appKernel;

$appKernel->container()->register(AppKernelInterface::class, $callback);
$appKernel->container()->register(KernelInterface::class, $callback);
}
}

0 comments on commit 44049f8

Please sign in to comment.