PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.27
Booking for Appointments and Events Calendar – Amelia v1.2.27
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Services / Frontend / LessParserService.php
ameliabooking / src / Infrastructure / Services / Frontend Last commit date
LessParserService.php 1 year ago
LessParserService.php
86 lines
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Infrastructure\Services\Frontend;
9
10 use AmeliaBooking\Domain\Services\Settings\SettingsService;
11 use Exception;
12 use Less_Exception_Parser;
13 use Less_Parser;
14
15 /**
16 * Class LessParserService
17 */
18 class LessParserService
19 {
20 /** @var string */
21 private $inputCssScript;
22
23 /** @var string */
24 private $outputPath;
25
26 /** @var SettingsService */
27 private $settingsService;
28
29 /**
30 * LessParserService constructor.
31 *
32 * @param string $inputCssScript
33 * @param string $outputPath
34 * @param SettingsService $settingsService
35 */
36 public function __construct($inputCssScript, $outputPath, $settingsService)
37 {
38 $this->inputCssScript = $inputCssScript;
39 $this->outputPath = $outputPath;
40 $this->settingsService = $settingsService;
41 }
42
43 /**
44 * @param array $data
45 *
46 * @return string
47 * @throws Exception
48 * @throws Less_Exception_Parser
49 */
50 public function compileAndSave($data)
51 {
52 $parser = new Less_Parser();
53
54 $parser->parseFile($this->inputCssScript);
55
56 $parser->ModifyVars($data);
57
58 !is_dir($this->outputPath) && !mkdir($this->outputPath, 0755, true) && !is_dir($this->outputPath);
59
60 $hash = $this->generateRandomString();
61
62 file_put_contents($this->outputPath . '/amelia-booking.' . $hash . '.css', $parser->getCss());
63
64 return $hash;
65 }
66
67 /**
68 * @param int $length
69 *
70 * @return false|string
71 */
72 public function generateRandomString($length = 10)
73 {
74 return substr(
75 str_shuffle(
76 str_repeat(
77 $x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
78 ceil($length / strlen($x))
79 )
80 ),
81 1,
82 $length
83 );
84 }
85 }
86