ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilSystemStyleLessFile Class Reference
+ Collaboration diagram for ilSystemStyleLessFile:

Public Member Functions

 __construct ($less_variables_file)
 KitchenSinkLessFile constructor. More...
 
 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 ($category="")
 
 getItemById ($id)
 
 getVariableByName ($name="")
 
 getReferencesToVariable ($variable_name)
 
 getReferencesToVariableAsString ($variable_name)
 
 getLessVariablesFile ()
 
 setLessVariablesFile ($less_variables_file)
 
 getItems ()
 
 getCommentsIds ()
 
 getVariablesIds ()
 
 getCategoriesIds ()
 

Protected Attributes

 $items = array()
 
 $comments_ids = array()
 
 $variables_ids = array()
 
 $categories_ids = array()
 
 $less_variables_file_path = ""
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilSystemStyleLessFile::__construct (   $less_variables_file)

KitchenSinkLessFile constructor.

Parameters
string$less_variables_file

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

58 {
59 $this->less_variables_file = $less_variables_file;
60 $this->read();
61 }
read()
Reads the file from the file system.

References read().

+ Here is the call graph for this function:

Member Function Documentation

◆ addItem()

ilSystemStyleLessFile::addItem ( ilSystemStyleLessItem  $item)
Parameters
ilSystemStyleLessItem$item
Returns
int

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

176 {
177 $id = array_push($this->items, $item)-1;
178
179
180 if (get_class($item)=="ilSystemStyleLessComment") {
181 $this->comments_ids[] = $id;
182 } elseif (get_class($item)=="ilSystemStyleLessCategory") {
183 $this->categories_ids[] = $id;
184 } elseif (get_class($item)=="ilSystemStyleLessVariable") {
185 $this->variables_ids[] = $id;
186 }
187
188 return $id;
189 }
if(!array_key_exists('StateId', $_REQUEST)) $id

References $id.

Referenced by read().

+ Here is the caller graph for this function:

◆ getCategories()

ilSystemStyleLessFile::getCategories ( )
Returns
ilSystemStyleLessCategory[]

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

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

◆ getCategoriesIds()

ilSystemStyleLessFile::getCategoriesIds ( )
Returns
array

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

References $categories_ids.

◆ getCommentsIds()

ilSystemStyleLessFile::getCommentsIds ( )
Returns
array

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

References $comments_ids.

◆ getContent()

ilSystemStyleLessFile::getContent ( )
Returns
string

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

162 {
163 $output = "";
164
165 foreach ($this->items as $item) {
166 $output .= $item->__toString();
167 }
168 return $output;
169 }
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output

References $output.

Referenced by write().

+ Here is the caller graph for this function:

◆ getItemById()

ilSystemStyleLessFile::getItemById (   $id)
Parameters
$id
Returns
ilSystemStyleLessVariable

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

227 {
228 return $this->items[$id];
229 }

References $id.

Referenced by read().

+ Here is the caller graph for this function:

◆ getItems()

ilSystemStyleLessFile::getItems ( )
Returns
ilSystemStyleLessVariable[]

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

References $items.

◆ getLessVariablesFile()

ilSystemStyleLessFile::getLessVariablesFile ( )
Returns
string

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

280 {
281 return $this->less_variables_file;
282 }

Referenced by read(), and write().

+ Here is the caller graph for this function:

◆ getReferencesToVariable()

ilSystemStyleLessFile::getReferencesToVariable (   $variable_name)
Parameters
$variable_name
Returns
array

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

250 {
251 $references = [];
252
253 foreach ($this->variables_ids as $id) {
254 foreach ($this->items[$id]->getReferences() as $reference) {
255 if ($variable_name == $reference) {
256 $references[] = $this->items[$id]->getName();
257 }
258 }
259 }
260 return $references;
261 }

References $id.

Referenced by getReferencesToVariableAsString().

+ Here is the caller graph for this function:

◆ getReferencesToVariableAsString()

ilSystemStyleLessFile::getReferencesToVariableAsString (   $variable_name)
Parameters
$variable_name
Returns
string

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

268 {
269 $references_string = "";
270 foreach ($this->getReferencesToVariable($variable_name) as $reference) {
271 $references_string .= "$reference; ";
272 }
273 return $references_string;
274 }

References getReferencesToVariable().

+ Here is the call graph for this function:

◆ getVariableByName()

ilSystemStyleLessFile::getVariableByName (   $name = "")
Parameters
string$name
Returns
ilSystemStyleLessVariable|null

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

236 {
237 foreach ($this->variables_ids as $variables_id) {
238 if ($this->items[$variables_id]->getName() == $name) {
239 return $this->items[$variables_id];
240 }
241 }
242 return null;
243 }
if($format !==null) $name
Definition: metadata.php:146

References $name.

◆ getVariablesIds()

ilSystemStyleLessFile::getVariablesIds ( )
Returns
array

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

References $variables_ids.

◆ getVariablesPerCategory()

ilSystemStyleLessFile::getVariablesPerCategory (   $category = "")
Parameters
string$category
Returns
ilSystemStyleLessVariable[]|null

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

210 {
211 $variables = array();
212
213 foreach ($this->variables_ids as $variables_id) {
214 if (!$category || $this->items[$variables_id]->getCategoryName() == $category) {
215 $variables[] = $this->items[$variables_id];
216 }
217 }
218
219 return $variables;
220 }

◆ read()

ilSystemStyleLessFile::read ( )

Reads the file from the file system.

Exceptions
ilSystemStyleException

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

69 {
70 $last_variable_comment = null;
71 $last_category_id = null;
72 $last_category_name = null;
73
74 $regex_category = '/\/\/==\s(.*)/'; //Matches //== Category Name
75 $regex_category_by_line = '/^\/\/[\s]?$/'; //Matches // at the end of the line with not comment
76 $regex_category_comment = '/\/\/##\s(.*)/'; //Matches Matches //## Category Description
77 $regex_variable = '/^@(.*)/'; //Matches @VariableName value;
78 $regex_variable_comment = '/\/\/\*\*\s(.*)/'; //Matches //** Variable Comment
79 $regex_variable_name = '/(?:@)(.*)(?:\:)/'; //Matches @variableName
80 $regex_variable_value = '/(?::)(.*)(?:;)/'; //Matches value;
81 $regex_variable_references = '/(?:@)([a-zA-Z0-9_-]*)/'; //Matches references in value
82
83 try {
84 $handle = fopen($this->getLessVariablesFile(), "r");
85 } catch (Exception $e) {
87 }
88
89
90 if ($handle) {
91 $line_number = 1;
92 $last_line_is_category = false;
93 //Reads file line by line
94 while (($line = fgets($handle)) !== false) {
95 //This might be part of the categories structure, if so, ignore
96 if ($last_line_is_category && preg_match($regex_category_by_line, $line, $out)) {
97 $line = fgets($handle);
98 }
99 $last_line_is_category = false;
100 if (preg_match($regex_category, $line, $out)) {
101 //Check Category
102 $last_category_id = $this->addItem(new ilSystemStyleLessCategory($out[1]));
103 $last_category_name = $out[1];
104 $last_line_is_category = true;
105 } elseif (preg_match($regex_category_comment, $line, $out)) {
106 //Check Comment Category
107 $last_category = $this->getItemById($last_category_id);
108 $last_category->setComment($out[1]);
109 } elseif (preg_match($regex_variable_comment, $line, $out)) {
110 //Check Variables Comment
111 $last_variable_comment = $out[1];
112 } elseif (preg_match($regex_variable, $line, $out)) {
113 //Check Variables
114
115 //Name
116 preg_match($regex_variable_name, $out[0], $variable);
117
118 //Value
119 preg_match($regex_variable_value, $line, $value);
120
121 //References
122 $temp_value = $value[0];
123 $references = array();
124 while (preg_match($regex_variable_references, $temp_value, $reference)) {
125 $references[] = $reference[1];
126 $temp_value = str_replace($reference, "", $temp_value);
127 }
128
130 $variable[1],
131 ltrim($value[1], " \t\n\r\0\x0B"),
132 $last_variable_comment,
133 $last_category_name,
134 $references
135 ));
136 $last_variable_comment = "";
137 } else {
138 $this->addItem(new ilSystemStyleLessComment($line));
139 }
140
141
142 $line_number++;
143 }
144 fclose($handle);
145 } else {
147 }
148 }
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 $out, addItem(), ilSystemStyleException\FILE_OPENING_FAILED, getItemById(), and getLessVariablesFile().

Referenced by __construct().

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

◆ setLessVariablesFile()

ilSystemStyleLessFile::setLessVariablesFile (   $less_variables_file)
Parameters
string$less_variables_file

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

288 {
289 $this->less_variables_file = $less_variables_file;
290 }

◆ write()

ilSystemStyleLessFile::write ( )

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

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

154 {
155 file_put_contents($this->getLessVariablesFile(), $this->getContent());
156 }

References getContent(), and getLessVariablesFile().

+ Here is the call graph for this function:

Field Documentation

◆ $categories_ids

ilSystemStyleLessFile::$categories_ids = array()
protected

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

Referenced by getCategoriesIds().

◆ $comments_ids

ilSystemStyleLessFile::$comments_ids = array()
protected

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

Referenced by getCommentsIds().

◆ $items

ilSystemStyleLessFile::$items = array()
protected

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

Referenced by getItems().

◆ $less_variables_file_path

ilSystemStyleLessFile::$less_variables_file_path = ""
protected

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

◆ $variables_ids

ilSystemStyleLessFile::$variables_ids = array()
protected

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

Referenced by getVariablesIds().


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