1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Webrouse\AssetMacro\DI; |
4
|
|
|
|
5
|
|
|
use Nette\DI\CompilerExtension; |
6
|
|
|
use Webrouse\AssetMacro\AssetMacro; |
7
|
|
|
use Webrouse\AssetMacro\Exceptions\UnexpectedValueException; |
8
|
|
|
|
9
|
|
|
class Extension extends CompilerExtension |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
public $defaults = [ |
13
|
|
|
'wwwDir' => '%wwwDir%', |
14
|
|
|
'versions' => AssetMacro::VERSIONS_AUTODETECT, |
15
|
|
|
'autodetectPaths' => [ |
16
|
|
|
'busters.json', |
17
|
|
|
'versions.json', |
18
|
|
|
'rev-manifest.json', |
19
|
|
|
], |
20
|
|
|
'missingAsset' => 'exception', // exception, notice, or ignore |
21
|
|
|
'missingVersion' => 'ignore', // exception, notice, or ignore |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
public function beforeCompile() |
25
|
|
|
{ |
26
|
1 |
|
$config = $this->getContainerBuilder()->expand($this->validateConfig($this->defaults)); |
|
|
|
|
27
|
|
|
|
28
|
1 |
View Code Duplication |
if (!in_array($config['missingAsset'], ['exception', 'notice', 'ignore'])) { |
|
|
|
|
29
|
1 |
|
throw new UnexpectedValueException(sprintf("Unexpected value '%s' of '%s' configuration key. Allowed values: 'exception', 'notice', 'ignore'.", $config['missingAsset'], $this->prefix('missingAsset'))); |
30
|
|
|
} |
31
|
1 |
View Code Duplication |
if (!in_array($config['missingVersion'], ['exception', 'notice', 'ignore'])) { |
|
|
|
|
32
|
1 |
|
throw new UnexpectedValueException(sprintf("Unexpected value '%s' of '%s' configuration key. Allowed values: 'exception', 'notice', 'ignore'.", $config['missingVersion'], $this->prefix('missingVersion'))); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
$builder = $this->getContainerBuilder(); |
36
|
1 |
|
$builder->getDefinition('latte.latteFactory') |
37
|
1 |
|
->addSetup("?->addProvider(?, ?)", ['@self', AssetMacro::CONFIG_PROVIDER, $config]) |
38
|
1 |
|
->addSetup("?->onCompile[] = function(\$engine) { " . |
39
|
1 |
|
AssetMacro::class . "::install(\$engine->getCompiler()); }", |
40
|
1 |
|
['@self'] |
41
|
|
|
); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
This method has been deprecated.