createEntryFilesTwigExtension()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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