Passed
Push — master ( 669e12...79866c )
by Marcel
08:09
created

WebpackEntryCssSourceExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Twig;
4
5
use Symfony\Contracts\Service\Attribute\SubscribedService;
6
use Symfony\Contracts\Service\ServiceSubscriberInterface;
7
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupInterface;
8
use Twig\Extension\AbstractExtension;
9
use Twig\TwigFunction;
10
11
class WebpackEntryCssSourceExtension extends AbstractExtension {
12
13
    public function __construct(private readonly EntrypointLookupInterface $entrypointLookup, private readonly string $publicDir) {
14
15
    }
16
17
    public function getFunctions() {
18
        return [
19
            new TwigFunction('css_source', [ $this, 'getCssSource'])
20
        ];
21
    }
22
23
    public function getCssSource(string $entryName): string {
24
        $files = $this->entrypointLookup->getCssFiles($entryName);
25
        $source = '';
26
27
        foreach($files as $file) {
28
            $source .= file_get_contents($this->publicDir . $file);
29
        }
30
31
        return $source;
32
    }
33
}