Total Complexity | 10 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
23 | class JsResolver implements ResolverInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var AssetBag |
||
27 | */ |
||
28 | private $bag; |
||
29 | |||
30 | /** |
||
31 | * @var MergerInterface |
||
32 | */ |
||
33 | private $merger; |
||
34 | |||
35 | /** |
||
36 | * @var bool |
||
37 | */ |
||
38 | private $combine; |
||
39 | |||
40 | public function __construct( |
||
41 | string $env, |
||
42 | AssetBag $bag, |
||
43 | MergerInterface $merger, |
||
44 | bool $combine = false |
||
45 | ) { |
||
46 | $this->bag = $bag; |
||
47 | $this->merger = $merger; |
||
48 | $this->combine = ('prod' === $env) && $combine; |
||
49 | } |
||
50 | |||
51 | public function compile(): string |
||
52 | { |
||
53 | $this->validateBag(); |
||
54 | $assets = $this->bag->allWithWeight(); |
||
55 | if ($this->combine) { |
||
56 | $assets = $this->merger->merge($assets); |
||
57 | } |
||
58 | $scripts = ''; |
||
59 | foreach ($assets as $asset => $weight) { |
||
60 | $scripts .= '<script src="' . $asset . '"></script>' . "\n"; |
||
61 | } |
||
62 | |||
63 | return $scripts; |
||
64 | } |
||
65 | |||
66 | public function getBag(): AssetBag |
||
69 | } |
||
70 | |||
71 | private function validateBag(): void |
||
84 |