|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Micro framework package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Stanislau Komar <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Micro\Plugin\Twig; |
|
13
|
|
|
|
|
14
|
|
|
use Micro\Component\DependencyInjection\Container; |
|
15
|
|
|
use Micro\Framework\Kernel\KernelInterface; |
|
16
|
|
|
use Micro\Framework\Kernel\Plugin\ConfigurableInterface; |
|
17
|
|
|
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface; |
|
18
|
|
|
use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait; |
|
19
|
|
|
use Micro\Plugin\Twig\Business\Environment\EnvironmentFactory; |
|
20
|
|
|
use Micro\Plugin\Twig\Business\Environment\EnvironmentFactoryInterface; |
|
21
|
|
|
use Micro\Plugin\Twig\Business\Loader\ExtensionLoader; |
|
22
|
|
|
use Micro\Plugin\Twig\Business\Loader\LoaderInterface; |
|
23
|
|
|
use Micro\Plugin\Twig\Business\Loader\LoaderProcessor; |
|
24
|
|
|
use Micro\Plugin\Twig\Business\Loader\LoaderProcessorInterface; |
|
25
|
|
|
use Micro\Plugin\Twig\Business\Loader\TemplateLoader; |
|
26
|
|
|
use Micro\Plugin\Twig\Business\Render\TwigRendererFactory; |
|
27
|
|
|
use Micro\Plugin\Twig\Business\Render\TwigRendererFactoryInterface; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @method TwigPluginConfigurationInterface configuration() |
|
31
|
|
|
*/ |
|
32
|
|
|
class TwigPlugin implements DependencyProviderInterface, ConfigurableInterface |
|
33
|
|
|
{ |
|
34
|
|
|
use PluginConfigurationTrait; |
|
35
|
|
|
|
|
36
|
|
|
private KernelInterface $kernel; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritDoc} |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function provideDependencies(Container $container): void |
|
42
|
|
|
{ |
|
43
|
1 |
|
$container->register(TwigFacadeInterface::class, function ( |
|
44
|
1 |
|
KernelInterface $kernel |
|
45
|
1 |
|
) { |
|
46
|
1 |
|
$this->kernel = $kernel; |
|
47
|
|
|
|
|
48
|
1 |
|
return $this->createTwigFacade(); |
|
49
|
1 |
|
}); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
protected function createTwigFacade(): TwigFacadeInterface |
|
53
|
|
|
{ |
|
54
|
1 |
|
return new TwigFacade( |
|
55
|
1 |
|
$this->createTwigRendererFactory() |
|
56
|
1 |
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
protected function createTwigRendererFactory(): TwigRendererFactoryInterface |
|
60
|
|
|
{ |
|
61
|
1 |
|
return new TwigRendererFactory( |
|
62
|
1 |
|
$this->createEnvironmentFactory() |
|
63
|
1 |
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
protected function createEnvironmentFactory(): EnvironmentFactoryInterface |
|
67
|
|
|
{ |
|
68
|
1 |
|
return new EnvironmentFactory( |
|
69
|
1 |
|
$this->configuration(), |
|
70
|
1 |
|
$this->createLoaderProcessor() |
|
71
|
1 |
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
1 |
|
protected function createLoaderProcessor(): LoaderProcessorInterface |
|
75
|
|
|
{ |
|
76
|
1 |
|
return new LoaderProcessor($this->kernel, $this->createLoaders()); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return LoaderInterface[] |
|
81
|
|
|
*/ |
|
82
|
1 |
|
protected function createLoaders(): array |
|
83
|
|
|
{ |
|
84
|
1 |
|
return [ |
|
85
|
1 |
|
new ExtensionLoader(), |
|
86
|
1 |
|
new TemplateLoader(), |
|
87
|
1 |
|
]; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|