diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 index 90d3772..61e4808 --- a/composer.json +++ b/composer.json @@ -2,10 +2,10 @@ "name": "micro/plugin-twig", "description": "Micro Framework: Twig provider plugin", "type": "library", - "version": "0.1", + "version": "0.9", "require": { "twig/twig": "^3", - "micro/kernel-app": "^0.1" + "micro/kernel-app": "^1" }, "license": "MIT", "autoload": { diff --git a/phpcs.xml b/phpcs.xml old mode 100644 new mode 100755 diff --git a/src/Business/Environment/EnvironmentFactory.php b/src/Business/Environment/EnvironmentFactory.php old mode 100644 new mode 100755 diff --git a/src/Business/Environment/EnvironmentFactoryInterface.php b/src/Business/Environment/EnvironmentFactoryInterface.php old mode 100644 new mode 100755 diff --git a/src/Business/Loader/ExtensionLoader.php b/src/Business/Loader/ExtensionLoader.php old mode 100644 new mode 100755 index 6d97ec1..42471d8 --- a/src/Business/Loader/ExtensionLoader.php +++ b/src/Business/Loader/ExtensionLoader.php @@ -2,19 +2,15 @@ namespace Micro\Plugin\Twig\Business\Loader; -use Micro\Framework\Kernel\Plugin\ApplicationPluginInterface; use Micro\Plugin\Twig\Plugin\TwigExtensionPluginInterface; use Twig\Environment; class ExtensionLoader implements LoaderInterface { /** - * @param Environment $environment - * @param TwigExtensionPluginInterface $plugin - * - * @return void + * {@inheritDoc} */ - public function load(Environment $environment, mixed $plugin): void + public function load(Environment $environment, TwigExtensionPluginInterface $plugin): void { $this->provideExtensions($environment, $plugin); } @@ -35,7 +31,7 @@ protected function provideExtensions(Environment $environment, TwigExtensionPlug /** * {@inheritDoc} */ - public function supports(ApplicationPluginInterface $plugin): bool + public function supports(object $plugin): bool { return $plugin instanceof TwigExtensionPluginInterface; } diff --git a/src/Business/Loader/LoaderInterface.php b/src/Business/Loader/LoaderInterface.php old mode 100644 new mode 100755 index c1271af..156530f --- a/src/Business/Loader/LoaderInterface.php +++ b/src/Business/Loader/LoaderInterface.php @@ -2,8 +2,7 @@ namespace Micro\Plugin\Twig\Business\Loader; -use Micro\Framework\Kernel\Plugin\ApplicationPluginInterface; -use Micro\Plugin\Twig\Plugin\TwigTemplatePluginInterface; +use Micro\Plugin\Twig\Plugin\TwigExtensionPluginInterface; use Twig\Environment; use Twig\Error\Error; @@ -11,18 +10,18 @@ interface LoaderInterface { /** * @param Environment $environment - * @param mixed $plugin + * @param object $plugin * * @throws Error * * @return void */ - public function load(Environment $environment, $plugin): void; + public function load(Environment $environment, TwigExtensionPluginInterface $plugin): void; /** - * @param ApplicationPluginInterface $plugin + * @param object $plugin * * @return bool */ - public function supports(ApplicationPluginInterface $plugin): bool; + public function supports(object $plugin): bool; } diff --git a/src/Business/Loader/LoaderProcessor.php b/src/Business/Loader/LoaderProcessor.php old mode 100644 new mode 100755 index 957fcc7..79e8108 --- a/src/Business/Loader/LoaderProcessor.php +++ b/src/Business/Loader/LoaderProcessor.php @@ -3,8 +3,6 @@ namespace Micro\Plugin\Twig\Business\Loader; use Micro\Framework\Kernel\KernelInterface; -use Micro\Framework\Kernel\Plugin\ApplicationPluginInterface; -use Micro\Plugin\Twig\Plugin\TwigExtensionPluginInterface; use Twig\Environment; class LoaderProcessor implements LoaderProcessorInterface @@ -14,8 +12,8 @@ class LoaderProcessor implements LoaderProcessorInterface * @param LoaderInterface[] $loaders */ public function __construct( - private KernelInterface $appKernel, - private iterable $loaders + private readonly KernelInterface $appKernel, + private readonly iterable $loaders ) { } @@ -32,10 +30,10 @@ public function load(Environment $environment): void /** * @param Environment $environment - * @param ApplicationPluginInterface $plugin + * @param object $plugin * @return void */ - protected function process(Environment $environment, ApplicationPluginInterface $plugin): void + protected function process(Environment $environment, object $plugin): void { foreach ($this->loaders as $loader) { if(!$loader->supports($plugin)) { diff --git a/src/Business/Loader/LoaderProcessorInterface.php b/src/Business/Loader/LoaderProcessorInterface.php old mode 100644 new mode 100755 diff --git a/src/Business/Loader/TemplateLoader.php b/src/Business/Loader/TemplateLoader.php old mode 100644 new mode 100755 index 1edd023..471926b --- a/src/Business/Loader/TemplateLoader.php +++ b/src/Business/Loader/TemplateLoader.php @@ -2,7 +2,6 @@ namespace Micro\Plugin\Twig\Business\Loader; -use Micro\Framework\Kernel\Plugin\ApplicationPluginInterface; use Micro\Plugin\Twig\Plugin\TwigTemplatePluginInterface; use Twig\Environment; use Twig\Error\LoaderError; @@ -20,7 +19,6 @@ class TemplateLoader implements LoaderInterface */ public function load(Environment $environment, mixed $plugin): void { - /** @var FilesystemLoader $loader */ $loader = $environment->getLoader(); $namespace = $plugin->getTwigNamespace(); @@ -48,7 +46,7 @@ protected function registerTemplates(FilesystemLoader $loader, array $paths, str /** * {@inheritDoc} */ - public function supports(ApplicationPluginInterface $plugin): bool + public function supports(object $plugin): bool { return $plugin instanceof TwigTemplatePluginInterface; } diff --git a/src/Business/Render/TwigRenderer.php b/src/Business/Render/TwigRenderer.php old mode 100644 new mode 100755 index 7016398..d939e24 --- a/src/Business/Render/TwigRenderer.php +++ b/src/Business/Render/TwigRenderer.php @@ -10,7 +10,7 @@ class TwigRenderer implements TwigRendererInterface * @param EnvironmentFactoryInterface $environmentFactory */ public function __construct( - private EnvironmentFactoryInterface $environmentFactory + private readonly EnvironmentFactoryInterface $environmentFactory ) { } diff --git a/src/Business/Render/TwigRendererFactory.php b/src/Business/Render/TwigRendererFactory.php old mode 100644 new mode 100755 diff --git a/src/Business/Render/TwigRendererFactoryInterface.php b/src/Business/Render/TwigRendererFactoryInterface.php old mode 100644 new mode 100755 diff --git a/src/Business/Render/TwigRendererInterface.php b/src/Business/Render/TwigRendererInterface.php old mode 100644 new mode 100755 diff --git a/src/Plugin/TwigExtensionPluginInterface.php b/src/Plugin/TwigExtensionPluginInterface.php old mode 100644 new mode 100755 diff --git a/src/Plugin/TwigTemplatePluginInterface.php b/src/Plugin/TwigTemplatePluginInterface.php old mode 100644 new mode 100755 diff --git a/src/TwigFacade.php b/src/TwigFacade.php old mode 100644 new mode 100755 index 88086c1..f90ed50 --- a/src/TwigFacade.php +++ b/src/TwigFacade.php @@ -9,7 +9,7 @@ class TwigFacade implements TwigFacadeInterface /** * @param TwigRendererFactoryInterface $twigRendererFactory */ - public function __construct(private TwigRendererFactoryInterface $twigRendererFactory) + public function __construct(private readonly TwigRendererFactoryInterface $twigRendererFactory) { } diff --git a/src/TwigFacadeInterface.php b/src/TwigFacadeInterface.php old mode 100644 new mode 100755 index 8bc272c..5d48b76 --- a/src/TwigFacadeInterface.php +++ b/src/TwigFacadeInterface.php @@ -13,7 +13,7 @@ interface TwigFacadeInterface * @param array $arguments * * @return string - *@throws RuntimeError + * @throws RuntimeError * @throws SyntaxError * * @throws LoaderError diff --git a/src/TwigPlugin.php b/src/TwigPlugin.php old mode 100644 new mode 100755 index 1058e86..6c80b44 --- a/src/TwigPlugin.php +++ b/src/TwigPlugin.php @@ -3,8 +3,10 @@ namespace Micro\Plugin\Twig; use Micro\Component\DependencyInjection\Container; -use Micro\Framework\Kernel\Plugin\AbstractPlugin; -use Micro\Kernel\App\AppKernelInterface; +use Micro\Framework\Kernel\KernelInterface; +use Micro\Framework\Kernel\Plugin\ConfigurableInterface; +use Micro\Framework\Kernel\Plugin\DependencyProviderInterface; +use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait; use Micro\Plugin\Twig\Business\Environment\EnvironmentFactory; use Micro\Plugin\Twig\Business\Environment\EnvironmentFactoryInterface; use Micro\Plugin\Twig\Business\Loader\LoaderInterface; @@ -18,18 +20,25 @@ /** * @method TwigPluginConfigurationInterface configuration() */ -class TwigPlugin extends AbstractPlugin +class TwigPlugin implements DependencyProviderInterface, ConfigurableInterface { - protected ?Container $container = null; + use PluginConfigurationTrait; + + /** + * @var KernelInterface + */ + private readonly KernelInterface $kernel; /** * {@inheritDoc} */ public function provideDependencies(Container $container): void { - $this->container = $container; + $container->register(TwigFacadeInterface::class, function ( + KernelInterface $kernel + ) { + $this->kernel = $kernel; - $container->register(TwigFacadeInterface::class, function (Container $container) { return $this->createTwigFacade(); }); } @@ -70,9 +79,7 @@ protected function createEnvironmentFactory(): EnvironmentFactoryInterface */ protected function createLoaderProcessor(): LoaderProcessorInterface { - $kernel = $this->lookupKernel(); - - return new LoaderProcessor($kernel, $this->createLoaders()); + return new LoaderProcessor($this->kernel, $this->createLoaders()); } /** @@ -85,12 +92,4 @@ protected function createLoaders(): array new TemplateLoader(), ]; } - - /** - * @return AppKernelInterface - */ - protected function lookupKernel(): AppKernelInterface - { - return $this->container->get(AppKernelInterface::class); - } } diff --git a/src/TwigPluginConfiguration.php b/src/TwigPluginConfiguration.php old mode 100644 new mode 100755 diff --git a/src/TwigPluginConfigurationInterface.php b/src/TwigPluginConfigurationInterface.php old mode 100644 new mode 100755