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

WebpackEntryCssSourceExtension::getCssSource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
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
}