Skip to content

Commit

Permalink
Merge pull request #1 from Micro-PHP/release-0.9
Browse files Browse the repository at this point in the history
v0.9 release - not for production.
  • Loading branch information
Asisyas authored Nov 25, 2022
2 parents 84f9e44 + 1e632bb commit b736b52
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 44 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions composer.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Empty file modified phpcs.xml
100644 → 100755
Empty file.
Empty file modified src/Business/Environment/EnvironmentFactory.php
100644 → 100755
Empty file.
Empty file modified src/Business/Environment/EnvironmentFactoryInterface.php
100644 → 100755
Empty file.
10 changes: 3 additions & 7 deletions src/Business/Loader/ExtensionLoader.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand Down
11 changes: 5 additions & 6 deletions src/Business/Loader/LoaderInterface.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

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;

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;
}
10 changes: 4 additions & 6 deletions src/Business/Loader/LoaderProcessor.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
{
}
Expand All @@ -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)) {
Expand Down
Empty file modified src/Business/Loader/LoaderProcessorInterface.php
100644 → 100755
Empty file.
4 changes: 1 addition & 3 deletions src/Business/Loader/TemplateLoader.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Business/Render/TwigRenderer.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TwigRenderer implements TwigRendererInterface
* @param EnvironmentFactoryInterface $environmentFactory
*/
public function __construct(
private EnvironmentFactoryInterface $environmentFactory
private readonly EnvironmentFactoryInterface $environmentFactory
)
{
}
Expand Down
Empty file modified src/Business/Render/TwigRendererFactory.php
100644 → 100755
Empty file.
Empty file modified src/Business/Render/TwigRendererFactoryInterface.php
100644 → 100755
Empty file.
Empty file modified src/Business/Render/TwigRendererInterface.php
100644 → 100755
Empty file.
Empty file modified src/Plugin/TwigExtensionPluginInterface.php
100644 → 100755
Empty file.
Empty file modified src/Plugin/TwigTemplatePluginInterface.php
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/TwigFacade.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TwigFacade implements TwigFacadeInterface
/**
* @param TwigRendererFactoryInterface $twigRendererFactory
*/
public function __construct(private TwigRendererFactoryInterface $twigRendererFactory)
public function __construct(private readonly TwigRendererFactoryInterface $twigRendererFactory)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/TwigFacadeInterface.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface TwigFacadeInterface
* @param array $arguments
*
* @return string
*@throws RuntimeError
* @throws RuntimeError
* @throws SyntaxError
*
* @throws LoaderError
Expand Down
33 changes: 16 additions & 17 deletions src/TwigPlugin.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
});
}
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -85,12 +92,4 @@ protected function createLoaders(): array
new TemplateLoader(),
];
}

/**
* @return AppKernelInterface
*/
protected function lookupKernel(): AppKernelInterface
{
return $this->container->get(AppKernelInterface::class);
}
}
Empty file modified src/TwigPluginConfiguration.php
100644 → 100755
Empty file.
Empty file modified src/TwigPluginConfigurationInterface.php
100644 → 100755
Empty file.

0 comments on commit b736b52

Please sign in to comment.