ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ilSystemStyleLessFile Class Reference
+ Collaboration diagram for ilSystemStyleLessFile:

Public Member Functions

 __construct (string $less_variables_file_path_name)
 
 read ()
 Reads the file from the file system. More...
 
 write ()
 Write the complete file back to the file system (including comments and random content) More...
 
 getContent ()
 
 addItem (ilSystemStyleLessItem $item)
 
 getCategories ()
 
 getVariablesPerCategory (string $category='')
 
 getItemById (int $id)
 
 getVariableByName (string $name='')
 
 getReferencesToVariable (string $variable_name)
 
 getReferencesToVariableAsString (string $variable_name)
 
 getRefAndCommentAsString (string $variable_name, string $refs_wording)
 
 getLessVariablesFilePathName ()
 
 setLessVariablesFilePathName (string $less_variables_file_path_name)
 
 getItems ()
 
 getCommentsIds ()
 
 getVariablesIds ()
 
 getCategoriesIds ()
 

Protected Attributes

array $items = []
 
array $comments_ids = []
 Separated array with all comments ids (performance reasons) More...
 
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 $less_variables_file_path_name = ''
 Complete path the the variables file on the file system. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleLessFile::__construct ( string  $less_variables_file_path_name)

Definition at line 53 of file class.ilSystemStyleLessFile.php.

54 {
55 $this->less_variables_file_path_name = $less_variables_file_path_name;
56 $this->read();
57 }
string $less_variables_file_path_name
Complete path the the variables file on the file system.
read()
Reads the file from the file system.

References $less_variables_file_path_name, and read().

+ Here is the call graph for this function:

Member Function Documentation

◆ addItem()

ilSystemStyleLessFile::addItem ( ilSystemStyleLessItem  $item)

Definition at line 164 of file class.ilSystemStyleLessFile.php.

164 : int
165 {
166 $id = array_push($this->items, $item) - 1;
167
168 if (get_class($item) == 'ilSystemStyleLessComment') {
169 $this->comments_ids[] = $id;
170 } elseif (get_class($item) == 'ilSystemStyleLessCategory') {
171 $this->categories_ids[] = $id;
172 } elseif (get_class($item) == 'ilSystemStyleLessVariable') {
173 $this->variables_ids[] = $id;
174 }
175
176 return $id;
177 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

Referenced by read().

+ Here is the caller graph for this function:

◆ getCategories()

ilSystemStyleLessFile::getCategories ( )
Returns
ilSystemStyleLessCategory[]

Definition at line 182 of file class.ilSystemStyleLessFile.php.

182 : array
183 {
184 $categories = [];
185
186 foreach ($this->categories_ids as $category_id) {
187 $categories[] = $this->items[$category_id];
188 }
189
190 return $categories;
191 }

◆ getCategoriesIds()

ilSystemStyleLessFile::getCategoriesIds ( )

Definition at line 297 of file class.ilSystemStyleLessFile.php.

297 : array
298 {
300 }
array $categories_ids
Separated array with all category ids (performance reasons)

References $categories_ids.

◆ getCommentsIds()

ilSystemStyleLessFile::getCommentsIds ( )

Definition at line 287 of file class.ilSystemStyleLessFile.php.

287 : array
288 {
289 return $this->comments_ids;
290 }
array $comments_ids
Separated array with all comments ids (performance reasons)

References $comments_ids.

◆ getContent()

ilSystemStyleLessFile::getContent ( )

Definition at line 154 of file class.ilSystemStyleLessFile.php.

154 : string
155 {
156 $output = '';
157
158 foreach ($this->items as $item) {
159 $output .= $item->__toString();
160 }
161 return $output;
162 }

Referenced by write().

+ Here is the caller graph for this function:

◆ getItemById()

ilSystemStyleLessFile::getItemById ( int  $id)

Definition at line 209 of file class.ilSystemStyleLessFile.php.

210 {
211 return $this->items[$id];
212 }
Abstracts content of a less file.

References $id.

Referenced by read().

+ Here is the caller graph for this function:

◆ getItems()

ilSystemStyleLessFile::getItems ( )
Returns
ilSystemStyleLessVariable[]

Definition at line 282 of file class.ilSystemStyleLessFile.php.

282 : array
283 {
284 return $this->items;
285 }

References $items.

◆ getLessVariablesFilePathName()

ilSystemStyleLessFile::getLessVariablesFilePathName ( )

Definition at line 269 of file class.ilSystemStyleLessFile.php.

269 : string
270 {
272 }

References $less_variables_file_path_name.

Referenced by read(), and write().

+ Here is the caller graph for this function:

◆ getRefAndCommentAsString()

ilSystemStyleLessFile::getRefAndCommentAsString ( string  $variable_name,
string  $refs_wording 
)

Definition at line 247 of file class.ilSystemStyleLessFile.php.

247 : string
248 {
249 $references_string = '';
250 foreach ($this->getReferencesToVariable($variable_name) as $reference) {
251 $references_string .= "$reference; ";
252 }
253
254 $variable = $this->getVariableByName($variable_name);
255
256 if ($references_string != '') {
257 if ($variable->getComment()) {
258 $info = $variable->getComment() . '</br>' . $refs_wording . ' ' . $references_string;
259 } else {
260 $info = $refs_wording . ' ' . $references_string;
261 }
262 } else {
263 $info = $variable->getComment();
264 }
265
266 return $info;
267 }
getReferencesToVariable(string $variable_name)

References getReferencesToVariable(), and getVariableByName().

+ Here is the call graph for this function:

◆ getReferencesToVariable()

ilSystemStyleLessFile::getReferencesToVariable ( string  $variable_name)

Definition at line 224 of file class.ilSystemStyleLessFile.php.

224 : array
225 {
226 $references = [];
227
228 foreach ($this->variables_ids as $id) {
229 foreach ($this->items[$id]->getReferences() as $reference) {
230 if ($variable_name == $reference) {
231 $references[] = $this->items[$id]->getName();
232 }
233 }
234 }
235 return $references;
236 }

References $id.

Referenced by getRefAndCommentAsString(), and getReferencesToVariableAsString().

+ Here is the caller graph for this function:

◆ getReferencesToVariableAsString()

ilSystemStyleLessFile::getReferencesToVariableAsString ( string  $variable_name)

Definition at line 238 of file class.ilSystemStyleLessFile.php.

238 : string
239 {
240 $references_string = '';
241 foreach ($this->getReferencesToVariable($variable_name) as $reference) {
242 $references_string .= "$reference; ";
243 }
244 return $references_string;
245 }

References getReferencesToVariable().

+ Here is the call graph for this function:

◆ getVariableByName()

ilSystemStyleLessFile::getVariableByName ( string  $name = '')

Definition at line 214 of file class.ilSystemStyleLessFile.php.

215 {
216 foreach ($this->variables_ids as $variables_id) {
217 if ($this->items[$variables_id]->getName() == $name) {
218 return $this->items[$variables_id];
219 }
220 }
221 return null;
222 }
if($format !==null) $name
Definition: metadata.php:247

References $name.

Referenced by getRefAndCommentAsString().

+ Here is the caller graph for this function:

◆ getVariablesIds()

ilSystemStyleLessFile::getVariablesIds ( )

Definition at line 292 of file class.ilSystemStyleLessFile.php.

292 : array
293 {
295 }
array $variables_ids
Separated array with all variable ids (performance reasons)

References $variables_ids.

◆ getVariablesPerCategory()

ilSystemStyleLessFile::getVariablesPerCategory ( string  $category = '')
Returns
ilSystemStyleLessVariable[]

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

196 : array
197 {
198 $variables = [];
199
200 foreach ($this->variables_ids as $variables_id) {
201 if (!$category || $this->items[$variables_id]->getCategoryName() == $category) {
202 $variables[] = $this->items[$variables_id];
203 }
204 }
205
206 return $variables;
207 }

◆ read()

ilSystemStyleLessFile::read ( )

Reads the file from the file system.

Exceptions
ilSystemStyleException

Definition at line 63 of file class.ilSystemStyleLessFile.php.

63 : void
64 {
65 $last_variable_comment = '';
66 $last_category_id = '';
67 $last_category_name = '';
68
69 $regex_category = '/\/\/==\s(.*)/'; //Matches //== Category Name
70 $regex_category_by_line = '/^\/\/[\s]?$/'; //Matches // at the end of the line with not comment
71 $regex_category_comment = '/\/\/##\s(.*)/'; //Matches Matches //## Category Description
72 $regex_variable = '/^@(.*)/'; //Matches @VariableName value;
73 $regex_variable_comment = '/\/\/\*\*\s(.*)/'; //Matches //** Variable Comment
74 $regex_variable_name = '/(?:@)(.*)(?:\:)/'; //Matches @variableName
75 $regex_variable_value = '/(?::)(.*)(?:;)/'; //Matches value;
76 $regex_variable_references = '/(?:@)([a-zA-Z0-9_-]*)/'; //Matches references in value
77
78 try {
79 $handle = fopen($this->getLessVariablesFilePathName(), 'r');
80 } catch (Exception $e) {
81 throw new ilSystemStyleException(
84 );
85 }
86
87 if ($handle) {
88 $line_number = 1;
89 $last_line_is_category = false;
90 //Reads file line by line
91 while (($line = fgets($handle)) !== false) {
92 //This might be part of the categories structure, if so, ignore
93 if ($last_line_is_category && preg_match($regex_category_by_line, $line, $out)) {
94 $line = fgets($handle);
95 }
96 $last_line_is_category = false;
97 if (preg_match($regex_category, $line, $out)) {
98 //Check Category
99 $last_category_id = $this->addItem(new ilSystemStyleLessCategory($out[1]));
100 $last_category_name = $out[1] ?: '';
101 $last_line_is_category = true;
102 } elseif (preg_match($regex_category_comment, $line, $out)) {
103 //Check Comment Category
104 $last_category = $this->getItemById($last_category_id);
105 $last_category->setComment($out[1]);
106 } elseif (preg_match($regex_variable_comment, $line, $out)) {
107 //Check Variables Comment
108 $last_variable_comment = $out[1];
109 } elseif (preg_match($regex_variable, $line, $out)) {
110 //Check Variables
111
112 //Name
113 preg_match($regex_variable_name, $out[0], $variable);
114
115 //Value
116 preg_match($regex_variable_value, $line, $value);
117
118 //References
119 $temp_value = $value[0];
120 $references = [];
121 while (preg_match($regex_variable_references, $temp_value, $reference)) {
122 $references[] = $reference[1];
123 $temp_value = str_replace($reference, '', $temp_value);
124 }
125
127 $variable[1],
128 ltrim($value[1]),
129 $last_variable_comment,
130 $last_category_name,
131 $references
132 ));
133 $last_variable_comment = '';
134 } else {
135 $this->addItem(new ilSystemStyleLessComment($line));
136 }
137
138 $line_number++;
139 }
140 fclose($handle);
141 } else {
143 }
144 }
$out
Definition: buildRTE.php:24
Class for advanced editing exception handling in ILIAS.
Capsules data of a less category in the variables to less file.
Capsules all data which is neither part of a variable or category structure in the less file.
addItem(ilSystemStyleLessItem $item)

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

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLessVariablesFilePathName()

ilSystemStyleLessFile::setLessVariablesFilePathName ( string  $less_variables_file_path_name)

Definition at line 274 of file class.ilSystemStyleLessFile.php.

274 : void
275 {
276 $this->less_variables_file_path_name = $less_variables_file_path_name;
277 }

References $less_variables_file_path_name.

◆ write()

ilSystemStyleLessFile::write ( )

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

Definition at line 149 of file class.ilSystemStyleLessFile.php.

149 : void
150 {
151 file_put_contents($this->getLessVariablesFilePathName(), $this->getContent());
152 }

References getContent(), and getLessVariablesFilePathName().

+ Here is the call graph for this function:

Field Documentation

◆ $categories_ids

array ilSystemStyleLessFile::$categories_ids = []
protected

Separated array with all category ids (performance reasons)

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

Referenced by getCategoriesIds().

◆ $comments_ids

array ilSystemStyleLessFile::$comments_ids = []
protected

Separated array with all comments ids (performance reasons)

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

Referenced by getCommentsIds().

◆ $items

array ilSystemStyleLessFile::$items = []
protected

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

Referenced by getItems().

◆ $less_variables_file_path_name

string ilSystemStyleLessFile::$less_variables_file_path_name = ''
protected

Complete path the the variables file on the file system.

Definition at line 51 of file class.ilSystemStyleLessFile.php.

Referenced by __construct(), getLessVariablesFilePathName(), and setLessVariablesFilePathName().

◆ $variables_ids

array ilSystemStyleLessFile::$variables_ids = []
protected

Separated array with all variable ids (performance reasons)

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

Referenced by getVariablesIds().


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