1 | <?php |
||
13 | class ScssAssetConverter extends Component implements AssetConverterInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var Storage |
||
17 | */ |
||
18 | public $storage; |
||
19 | |||
20 | /** |
||
21 | * @var boolean whether the source asset file should be converted even if |
||
22 | * its result already exists. You may want to set this to be `true` during |
||
23 | * the development stage to make sure the converted assets are always up-to- |
||
24 | * date. Do not set this to true on production servers as it will |
||
25 | * significantly degrade the performance. |
||
26 | */ |
||
27 | public $forceConvert = false; |
||
28 | |||
29 | /** |
||
30 | * @var Compiler|mixed The mixed type hint is added to keep PHPStan happy, |
||
31 | * since Yii was annotated to return "object" which confuses PHPStan. |
||
32 | */ |
||
33 | private $compiler; |
||
34 | |||
35 | 14 | public function init() |
|
43 | |||
44 | /** |
||
45 | * Converts a given SCSS asset file into a CSS file. |
||
46 | * @param string $asset the asset file path, relative to $basePath |
||
47 | * @param string $basePath the directory the $asset is relative to. |
||
48 | * @return string the converted asset file path, relative to $basePath. |
||
49 | */ |
||
50 | 13 | public function convert($asset, $basePath) |
|
72 | |||
73 | 13 | private function getExtension(string $filename): string |
|
77 | |||
78 | /** |
||
79 | * Get the relative path and filename of the asset |
||
80 | * @param string $filename e.g. path/asset.css |
||
81 | * @param string $newExtension e.g. scss |
||
82 | * @return string e.g. path/asset.scss |
||
83 | */ |
||
84 | 9 | protected function getCssAsset(string $filename, string $newExtension): string |
|
91 | |||
92 | 10 | private function convertAndSaveIfNeeded(string $inFile, string $outFile) |
|
99 | |||
100 | 10 | private function shouldConvert(string $inFile, string $outFile): bool |
|
115 | |||
116 | 3 | private function isOlder(string $fileA, string $fileB): bool |
|
120 | } |
||
121 |