EntryFilesTwigExtension::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\Twig\Extension;
13
14
use OleksiiBulba\WebpackEncorePlugin\Asset\EntrypointLookupInterface;
15
use OleksiiBulba\WebpackEncorePlugin\TagRenderer\TagRendererInterface;
16
use Twig\Extension\AbstractExtension;
17
use Twig\TwigFunction;
18
19
/**
20
 * @codeCoverageIgnore
21
 */
22
class EntryFilesTwigExtension extends AbstractExtension
23
{
24
    public function __construct(
25
        private readonly TagRendererInterface $tagRenderer,
26
        private readonly EntrypointLookupInterface $entrypointLookup
27
    ) {
28
    }
29
30
    /**
31
     * Returns twig functions for registering them in twig environment.
32
     *
33
     * There are 5 available twig functions:
34
     * - encore_entry_js_files
35
     * - encore_entry_css_files
36
     * - encore_entry_script_tags
37
     * - encore_entry_link_tags
38
     * - encore_entry_exists
39
     *
40
     * @return TwigFunction[]
41
     */
42
    public function getFunctions(): array
43
    {
44
        return [
45
            new TwigFunction('encore_entry_js_files', [$this->entrypointLookup, 'getJavaScriptFiles']),
46
            new TwigFunction('encore_entry_css_files', [$this->entrypointLookup, 'getCssFiles']),
47
            new TwigFunction('encore_entry_script_tags', [$this->tagRenderer, 'renderWebpackScriptTags'], ['is_safe' => ['html']]),
48
            new TwigFunction('encore_entry_link_tags', [$this->tagRenderer, 'renderWebpackLinkTags'], ['is_safe' => ['html']]),
49
            new TwigFunction('encore_entry_exists', [$this->entrypointLookup, 'entryExists']),
50
        ];
51
    }
52
}
53