19 declare(strict_types=1);
50 public function __construct(
string $scss_variables_settings_path,
string $file_name)
54 $this->
openFile($scss_variables_settings_path);
57 protected function openFile(
string $scss_variables_settings_path): void
59 if (is_file($scss_variables_settings_path.
'/'.$this->file_name)) {
60 $this->
readFile($scss_variables_settings_path);
64 $scss_variables_settings_path
72 protected function readFile(
string $scss_variables_settings_path): void
74 $last_variable_comment =
'';
75 $last_category_id =
'';
76 $last_category_name =
'';
78 $regex_category =
'/\/\/==\s(.*)/';
79 $regex_category_by_line =
'/^\/\/[\s]?$/';
80 $regex_category_comment =
'/\/\/##\s(.*)/';
81 $regex_variable =
'/^\$(.*)/';
82 $regex_variable_comment =
'/\/\/\*\*\s(.*)/';
83 $regex_variable_name =
'/(?:\$)(.*?)(?:\:)/';
84 $regex_variable_value =
'/(?::)(.*)(?:;)/';
85 $regex_variable_references =
'/(?:\$)([a-zA-Z0-9_-]*)/';
88 $handle = fopen($scss_variables_settings_path.
"/".$this->file_name,
'r');
92 $scss_variables_settings_path
98 $last_line_is_category =
false;
100 while (($line = fgets($handle)) !==
false) {
102 if ($last_line_is_category && preg_match($regex_category_by_line, $line,
$out)) {
103 $line = fgets($handle);
105 $last_line_is_category =
false;
106 if (preg_match($regex_category, $line,
$out)) {
109 $last_category_name =
$out[1] ?:
'';
110 $last_line_is_category =
true;
111 } elseif (preg_match($regex_category_comment, $line,
$out)) {
113 $last_category = $this->
getItemById($last_category_id);
114 $last_category->setComment(
$out[1]);
115 } elseif (preg_match($regex_variable_comment, $line,
$out)) {
117 $last_variable_comment =
$out[1];
118 } elseif (preg_match($regex_variable, $line,
$out)) {
121 preg_match($regex_variable_name,
$out[0], $variable);
124 preg_match($regex_variable_value, $line, $value);
127 $temp_value = $value[0];
129 while (preg_match($regex_variable_references, $temp_value, $reference)) {
130 $references[] = $reference[1];
131 $temp_value = str_replace($reference,
'', $temp_value);
135 $value = str_replace(
' !default',
'', ltrim($value[1]));
140 $last_variable_comment,
144 $last_variable_comment =
'';
160 public function write(
string $scss_variables_settings_path =
""): void
162 if ($scss_variables_settings_path ==
"") {
174 foreach ($this->items as $item) {
175 $output .= $item->__toString();
182 $id = array_push($this->items, $item) - 1;
184 if (get_class($item) == ilSystemStyleScssCategory::class) {
185 $this->categories_ids[] =
$id;
186 } elseif (get_class($item) == ilSystemStyleScssVariable::class) {
187 $this->variables_ids[] =
$id;
200 foreach ($this->categories_ids as $category_id) {
201 $category = $this->items[$category_id];
202 $categories[$category->getName()] = $category;
215 foreach ($this->variables_ids as $variable_id) {
216 $variable = $this->items[$variable_id];
217 $variables[$variable->getName()] = $variable;
225 return $this->items[
$id];
readFile(string $scss_variables_settings_path)
Reads the file from the file system.
array $categories_ids
Separated array with all category ids (performance reasons)
Abstracts content of a scss file.
Capsules data of a Scss category in the variables to Scss file.
write(string $scss_variables_settings_path="")
Write the complete file back to the file system (including comments and random content) ...
getScssVariablesSettingsPath()
__construct(string $scss_variables_settings_path, string $file_name)
array $variables_ids
Separated array with all variable ids (performance reasons)
addItem(ilSystemStyleScssItem $item)
string $scss_variables_settings_path
Complete path to the settings file.
const FILE_OPENING_FAILED
openFile(string $scss_variables_settings_path)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins