1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the WebpackEncore plugin for Micro Framework. |
7
|
|
|
* (c) Oleksii Bulba <[email protected]> |
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 OleksiiBulba\WebpackEncorePlugin; |
13
|
|
|
|
14
|
|
|
use Micro\Framework\Kernel\Plugin\ConfigurableInterface; |
15
|
|
|
use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait; |
16
|
|
|
use Micro\Framework\Kernel\Plugin\PluginDependedInterface; |
17
|
|
|
use Micro\Plugin\Twig\Plugin\TwigExtensionPluginInterface; |
18
|
|
|
use Micro\Plugin\Twig\TwigPlugin; |
19
|
|
|
use OleksiiBulba\WebpackEncorePlugin\Asset\EntrypointLookup; |
20
|
|
|
use OleksiiBulba\WebpackEncorePlugin\Asset\EntrypointLookupInterface; |
21
|
|
|
use OleksiiBulba\WebpackEncorePlugin\TagRenderer\TagRenderer; |
22
|
|
|
use OleksiiBulba\WebpackEncorePlugin\TagRenderer\TagRendererInterface; |
23
|
|
|
use OleksiiBulba\WebpackEncorePlugin\Twig\Extension\EntryFilesTwigExtension; |
24
|
|
|
use Symfony\Component\Serializer\Encoder\DecoderInterface; |
25
|
|
|
use Symfony\Component\Serializer\Encoder\JsonDecode; |
26
|
|
|
use Twig\Extension\ExtensionInterface; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @psalm-suppress ImplementedReturnTypeMismatch |
30
|
|
|
* |
31
|
|
|
* @method WebpackEncorePluginConfigurationInterface configuration() |
32
|
|
|
* |
33
|
|
|
* @codeCoverageIgnore |
34
|
|
|
*/ |
35
|
|
|
class WebpackEncorePlugin implements TwigExtensionPluginInterface, ConfigurableInterface, PluginDependedInterface |
36
|
|
|
{ |
37
|
|
|
use PluginConfigurationTrait; |
38
|
|
|
|
39
|
|
|
public function provideTwigExtensions(): iterable |
40
|
|
|
{ |
41
|
|
|
yield $this->createEntryFilesTwigExtension(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getDependedPlugins(): iterable |
45
|
|
|
{ |
46
|
|
|
yield TwigPlugin::class; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function createEntryFilesTwigExtension(): ExtensionInterface |
50
|
|
|
{ |
51
|
|
|
return new EntryFilesTwigExtension($this->createTagRenderer(), $this->createEntrypointLookup()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function createTagRenderer(): TagRendererInterface |
55
|
|
|
{ |
56
|
|
|
return new TagRenderer($this->createEntrypointLookup()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function createEntrypointLookup(): EntrypointLookupInterface |
60
|
|
|
{ |
61
|
|
|
return new EntrypointLookup($this->configuration(), $this->createDecoder()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function createDecoder(): DecoderInterface |
65
|
|
|
{ |
66
|
|
|
return new JsonDecode([JsonDecode::ASSOCIATIVE => true]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|