ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilSystemStyleScssSettingsFile Class Reference
+ Collaboration diagram for ilSystemStyleScssSettingsFile:

Public Member Functions

 __construct (string $scss_variables_settings_path, string $file_name)
 
 write (string $scss_variables_settings_path="")
 Write the complete file back to the file system (including comments and random content) More...
 
 getContent ()
 
 addItem (ilSystemStyleScssItem $item)
 
 getCategories ()
 
 getVariables ()
 
 getItems ()
 
 getScssVariablesSettingsPath ()
 

Protected Member Functions

 openFile (string $scss_variables_settings_path)
 
 readFile (string $scss_variables_settings_path)
 Reads the file from the file system. More...
 
 getItemById (int $id)
 

Protected Attributes

array $items = []
 
array $variables_ids = []
 Separated array with all variable ids (performance reasons) More...
 
array $categories_ids = []
 Separated array with all category ids (performance reasons) More...
 
string $scss_variables_settings_path
 Complete path to the settings file. More...
 
string $file_name
 

Detailed Description

Definition at line 25 of file class.ilSystemStyleScssSettingsFile.php.

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleScssSettingsFile::__construct ( string  $scss_variables_settings_path,
string  $file_name 
)

Definition at line 50 of file class.ilSystemStyleScssSettingsFile.php.

References $file_name, $scss_variables_settings_path, and openFile().

51  {
52  $this->file_name = $file_name;
53  $this->scss_variables_settings_path = $scss_variables_settings_path;
55  }
string $scss_variables_settings_path
Complete path to the settings file.
openFile(string $scss_variables_settings_path)
+ Here is the call graph for this function:

Member Function Documentation

◆ addItem()

ilSystemStyleScssSettingsFile::addItem ( ilSystemStyleScssItem  $item)

Definition at line 180 of file class.ilSystemStyleScssSettingsFile.php.

References $id.

Referenced by readFile().

180  : int
181  {
182  $id = array_push($this->items, $item) - 1;
183 
184  if (get_class($item) == ilSystemStyleScssCategory::class) {
185  $this->categories_ids[] = $id;
186  } elseif (get_class($item) == ilSystemStyleScssVariable::class) {
187  $this->variables_ids[] = $id;
188  }
189 
190  return $id;
191  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ getCategories()

ilSystemStyleScssSettingsFile::getCategories ( )
Returns
ilSystemStyleScssCategory[]

Definition at line 196 of file class.ilSystemStyleScssSettingsFile.php.

196  : array
197  {
198  $categories = [];
199 
200  foreach ($this->categories_ids as $category_id) {
201  $category = $this->items[$category_id];
202  $categories[$category->getName()] = $category;
203  }
204 
205  return $categories;
206  }

◆ getContent()

ilSystemStyleScssSettingsFile::getContent ( )

Definition at line 170 of file class.ilSystemStyleScssSettingsFile.php.

Referenced by write().

170  : string
171  {
172  $output = '';
173 
174  foreach ($this->items as $item) {
175  $output .= $item->__toString();
176  }
177  return $output;
178  }
+ Here is the caller graph for this function:

◆ getItemById()

ilSystemStyleScssSettingsFile::getItemById ( int  $id)
protected

Definition at line 223 of file class.ilSystemStyleScssSettingsFile.php.

References $id.

Referenced by readFile().

224  {
225  return $this->items[$id];
226  }
Abstracts content of a scss file.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ getItems()

ilSystemStyleScssSettingsFile::getItems ( )

Definition at line 228 of file class.ilSystemStyleScssSettingsFile.php.

References $items.

228  : array
229  {
230  return $this->items;
231  }

◆ getScssVariablesSettingsPath()

ilSystemStyleScssSettingsFile::getScssVariablesSettingsPath ( )
Returns
string

Definition at line 236 of file class.ilSystemStyleScssSettingsFile.php.

References $scss_variables_settings_path.

236  : string
237  {
239  }
string $scss_variables_settings_path
Complete path to the settings file.

◆ getVariables()

ilSystemStyleScssSettingsFile::getVariables ( )
Returns
ilSystemStyleScssCategory[]

Definition at line 211 of file class.ilSystemStyleScssSettingsFile.php.

211  : array
212  {
213  $variables = [];
214 
215  foreach ($this->variables_ids as $variable_id) {
216  $variable = $this->items[$variable_id];
217  $variables[$variable->getName()] = $variable;
218  }
219 
220  return $variables;
221  }

◆ openFile()

ilSystemStyleScssSettingsFile::openFile ( string  $scss_variables_settings_path)
protected

Definition at line 57 of file class.ilSystemStyleScssSettingsFile.php.

References ilSystemStyleException\FILE_OPENING_FAILED, and readFile().

Referenced by __construct().

57  : void
58  {
59  if (is_file($scss_variables_settings_path.'/'.$this->file_name)) {
61  } else {
62  throw new ilSystemStyleException(
65  );
66  }
67  }
readFile(string $scss_variables_settings_path)
Reads the file from the file system.
string $scss_variables_settings_path
Complete path to the settings file.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readFile()

ilSystemStyleScssSettingsFile::readFile ( string  $scss_variables_settings_path)
protected

Reads the file from the file system.

Exceptions
ilSystemStyleException

Definition at line 72 of file class.ilSystemStyleScssSettingsFile.php.

References Vendor\Package\$e, $out, addItem(), ilSystemStyleException\FILE_OPENING_FAILED, and getItemById().

Referenced by openFile().

72  : void
73  {
74  $last_variable_comment = '';
75  $last_category_id = '';
76  $last_category_name = '';
77 
78  $regex_category = '/\/\/==\s(.*)/'; //Matches //== Category Name
79  $regex_category_by_line = '/^\/\/[\s]?$/'; //Matches // at the end of the line with not comment
80  $regex_category_comment = '/\/\/##\s(.*)/'; //Matches Matches //## Category Description
81  $regex_variable = '/^\$(.*)/'; //Matches @VariableName value;
82  $regex_variable_comment = '/\/\/\*\*\s(.*)/'; //Matches //** Variable Comment
83  $regex_variable_name = '/(?:\$)(.*?)(?:\:)/'; //Matches @variableName
84  $regex_variable_value = '/(?::)(.*)(?:;)/'; //Matches value;
85  $regex_variable_references = '/(?:\$)([a-zA-Z0-9_-]*)/'; //Matches references in value
86 
87  try {
88  $handle = fopen($scss_variables_settings_path."/".$this->file_name, 'r');
89  } catch (Exception $e) {
90  throw new ilSystemStyleException(
93  );
94  }
95 
96  if ($handle) {
97  $line_number = 1;
98  $last_line_is_category = false;
99  //Reads file line by line
100  while (($line = fgets($handle)) !== false) {
101  //This might be part of the categories structure, if so, ignore
102  if ($last_line_is_category && preg_match($regex_category_by_line, $line, $out)) {
103  $line = fgets($handle);
104  }
105  $last_line_is_category = false;
106  if (preg_match($regex_category, $line, $out)) {
107  //Check Category
108  $last_category_id = $this->addItem(new ilSystemStyleScssCategory($out[1]));
109  $last_category_name = $out[1] ?: '';
110  $last_line_is_category = true;
111  } elseif (preg_match($regex_category_comment, $line, $out)) {
112  //Check Comment Category
113  $last_category = $this->getItemById($last_category_id);
114  $last_category->setComment($out[1]);
115  } elseif (preg_match($regex_variable_comment, $line, $out)) {
116  //Check Variables Comment
117  $last_variable_comment = $out[1];
118  } elseif (preg_match($regex_variable, $line, $out)) {
119  //Check Variables
120  //Name
121  preg_match($regex_variable_name, $out[0], $variable);
122 
123  //Value
124  preg_match($regex_variable_value, $line, $value);
125 
126  //References
127  $temp_value = $value[0];
128  $references = [];
129  while (preg_match($regex_variable_references, $temp_value, $reference)) {
130  $references[] = $reference[1];
131  $temp_value = str_replace($reference, '', $temp_value);
132  }
133 
134  //do not store the !default attribute in the variable
135  $value = str_replace(' !default', '', ltrim($value[1]));
136 
138  $variable[1],
139  $value,
140  $last_variable_comment,
141  $last_category_name,
142  $references
143  ));
144  $last_variable_comment = '';
145  } else {
146  $this->addItem(new ilSystemStyleScssComment($line));
147  }
148 
149  $line_number++;
150  }
151  fclose($handle);
152  } else {
154  }
155  }
Capsules data of a Scss category in the variables to Scss file.
Capsules all data which is neither part of a variable or category structure in the Scss file...
$out
Definition: buildRTE.php:24
string $scss_variables_settings_path
Complete path to the settings file.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write()

ilSystemStyleScssSettingsFile::write ( string  $scss_variables_settings_path = "")

Write the complete file back to the file system (including comments and random content)

Definition at line 160 of file class.ilSystemStyleScssSettingsFile.php.

References $path, $scss_variables_settings_path, and getContent().

160  : void
161  {
162  if ($scss_variables_settings_path == "") {
164  } else {
166  }
167  file_put_contents($path . $this->file_name, $this->getContent());
168  }
$path
Definition: ltiservices.php:32
string $scss_variables_settings_path
Complete path to the settings file.
+ Here is the call graph for this function:

Field Documentation

◆ $categories_ids

array ilSystemStyleScssSettingsFile::$categories_ids = []
protected

Separated array with all category ids (performance reasons)

Definition at line 41 of file class.ilSystemStyleScssSettingsFile.php.

◆ $file_name

string ilSystemStyleScssSettingsFile::$file_name
protected

Definition at line 48 of file class.ilSystemStyleScssSettingsFile.php.

Referenced by __construct().

◆ $items

array ilSystemStyleScssSettingsFile::$items = []
protected

Definition at line 31 of file class.ilSystemStyleScssSettingsFile.php.

Referenced by getItems().

◆ $scss_variables_settings_path

string ilSystemStyleScssSettingsFile::$scss_variables_settings_path
protected

Complete path to the settings file.

Definition at line 46 of file class.ilSystemStyleScssSettingsFile.php.

Referenced by __construct(), getScssVariablesSettingsPath(), and write().

◆ $variables_ids

array ilSystemStyleScssSettingsFile::$variables_ids = []
protected

Separated array with all variable ids (performance reasons)

Definition at line 36 of file class.ilSystemStyleScssSettingsFile.php.


The documentation for this class was generated from the following file: