1: <?php
2: namespace Opencart\Catalog\Controller\Startup;
3: /**
4: * Class Sass
5: *
6: * @package Opencart\Catalog\Controller\Startup
7: */
8: class Sass extends \Opencart\System\Engine\Controller {
9: /**
10: * @throws \Exception&\ScssPhp\ScssPhp\Exception\SassException
11: *
12: * @return void
13: */
14: public function index(): void {
15: $files = glob(DIR_APPLICATION . 'view/stylesheet/*.scss');
16:
17: if ($files) {
18: foreach ($files as $file) {
19: // Get the filename
20: $filename = basename($file, '.scss');
21:
22: $stylesheet = DIR_APPLICATION . 'view/stylesheet/' . $filename . '.css';
23:
24: if (!is_file($stylesheet) || !$this->config->get('developer_sass')) {
25: $scss = new \ScssPhp\ScssPhp\Compiler();
26: $scss->setImportPaths(DIR_APPLICATION . 'view/stylesheet/');
27:
28: $output = $scss->compileString('@import "' . $filename . '.scss"')->getCss();
29:
30: $handle = fopen($stylesheet, 'w');
31:
32: flock($handle, LOCK_EX);
33:
34: fwrite($handle, $output);
35:
36: fflush($handle);
37:
38: flock($handle, LOCK_UN);
39:
40: fclose($handle);
41: }
42: }
43: }
44: }
45: }
46: