|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Theme; |
|
4
|
|
|
|
|
5
|
|
|
use ScssPhp\ScssPhp\Compiler; |
|
6
|
|
|
use ScssPhp\ScssPhp\OutputStyle; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @internal - may be changed in the future |
|
10
|
|
|
*/ |
|
11
|
|
|
class ScssPhpCompiler extends AbstractScssCompiler |
|
12
|
|
|
{ |
|
13
|
|
|
private Compiler $compiler; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var array<string, mixed>|null |
|
17
|
|
|
*/ |
|
18
|
|
|
private ?array $cacheOptions; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @param array<string, mixed>|null $cacheOptions |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct(?array $cacheOptions = null) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->compiler = new Compiler($cacheOptions); |
|
26
|
|
|
$this->cacheOptions = $cacheOptions; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function reset(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->compiler = new Compiler($this->cacheOptions); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function compileString(AbstractCompilerConfiguration $config, string $scss, ?string $path = null): string |
|
35
|
|
|
{ |
|
36
|
|
|
$outputStyle = $config->getValue('outputStyle'); |
|
37
|
|
|
|
|
38
|
|
|
if ($outputStyle === OutputStyle::COMPRESSED || $outputStyle === OutputStyle::EXPANDED) { |
|
39
|
|
|
$this->compiler->setOutputStyle($outputStyle); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$importPaths = $config->getValue('importPaths'); |
|
43
|
|
|
|
|
44
|
|
|
if ($importPaths !== null) { |
|
45
|
|
|
$this->compiler->setImportPaths($importPaths); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$css = $this->compiler->compileString($scss, $path)->getCss(); |
|
49
|
|
|
|
|
50
|
|
|
$this->reset(); // Reset compiler for multiple usage |
|
51
|
|
|
|
|
52
|
|
|
return $css; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function filesHandledInternal(): bool |
|
56
|
|
|
{ |
|
57
|
|
|
return false; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|