ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 172 of file class.ilSystemStyleLessFile.php.

172 {
173 $id = array_push($this->items,$item)-1;
174
175
176 if(get_class($item)=="ilSystemStyleLessComment"){
177 $this->comments_ids[] = $id;
178 }else if(get_class($item)=="ilSystemStyleLessCategory"){
179 $this->categories_ids[] = $id;
180 }else if(get_class($item)=="ilSystemStyleLessVariable"){
181 $this->variables_ids[] = $id;
182 }
183
184 return $id;
185 }

Referenced by read().

+ Here is the caller graph for this function:

◆ getCategories()

ilSystemStyleLessFile::getCategories ( )
Returns
ilSystemStyleLessCategory[]

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

190 {
191 $categories = array();
192
193 foreach($this->categories_ids as $category_id){
194 $categories[] = $this->items[$category_id];
195 }
196
197 return $categories;
198
199 }

◆ getCategoriesIds()

ilSystemStyleLessFile::getCategoriesIds ( )
Returns
array

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

References $categories_ids.

◆ getCommentsIds()

ilSystemStyleLessFile::getCommentsIds ( )
Returns
array

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

References $comments_ids.

◆ getContent()

ilSystemStyleLessFile::getContent ( )
Returns
string

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

159 {
160 $output = "";
161
162 foreach($this->items as $item){
163 $output .= $item->__toString();
164 }
165 return $output;
166 }
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 221 of file class.ilSystemStyleLessFile.php.

221 {
222 return $this->items[$id];
223 }

Referenced by read().

+ Here is the caller graph for this function:

◆ getItems()

ilSystemStyleLessFile::getItems ( )
Returns
ilSystemStyleLessVariable[]

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

References $items.

◆ getLessVariablesFile()

ilSystemStyleLessFile::getLessVariablesFile ( )
Returns
string

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

271 {
272 return $this->less_variables_file;
273 }

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 243 of file class.ilSystemStyleLessFile.php.

243 {
244 $references = [];
245
246 foreach($this->variables_ids as $id){
247 foreach($this->items[$id]->getReferences() as $reference){
248 if($variable_name == $reference)
249 $references[] = $this->items[$id]->getName();
250 }
251 }
252 return $references;
253 }

Referenced by getReferencesToVariableAsString().

+ Here is the caller graph for this function:

◆ getReferencesToVariableAsString()

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

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

259 {
260 $references_string = "";
261 foreach($this->getReferencesToVariable($variable_name) as $reference){
262 $references_string .= "$reference; ";
263 }
264 return $references_string;
265 }

References getReferencesToVariable().

+ Here is the call graph for this function:

◆ getVariableByName()

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

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

229 {
230 foreach($this->variables_ids as $variables_id){
231 if($this->items[$variables_id]->getName() == $name){
232 return $this->items[$variables_id];
233 }
234 }
235 return null;
236
237 }

◆ getVariablesIds()

ilSystemStyleLessFile::getVariablesIds ( )
Returns
array

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

References $variables_ids.

◆ getVariablesPerCategory()

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

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

205 {
206 $variables = array();
207
208 foreach($this->variables_ids as $variables_id){
209 if(!$category || $this->items[$variables_id]->getCategoryName() == $category){
210 $variables[] = $this->items[$variables_id];
211 }
212 }
213
214 return $variables;
215 }

◆ read()

ilSystemStyleLessFile::read ( )

Reads the file from the file system.

Exceptions
ilSystemStyleException

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

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

279 {
280 $this->less_variables_file = $less_variables_file;
281 }

◆ write()

ilSystemStyleLessFile::write ( )

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

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

152 {
153 file_put_contents($this->getLessVariablesFile(),$this->getContent());
154 }

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: