ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilIniFile Class Reference

INIFile Parser. More...

+ Collaboration diagram for ilIniFile:

Public Member Functions

 ilIniFile ($a_ini_file_name)
 Constructor @access public. More...
 
 read ()
 read from ini file @access public More...
 
 parse ()
 load and parse an inifile @access private More...
 
 fixIniFile ()
 Fix ini file (make it compatible for PHP 5.3) More...
 
 parse_data ($a_data)
 parse data @access private More...
 
 setContent ($a_data)
 DESCRIPTION MISSING @access public. More...
 
 write ()
 save ini-file-data to filesystem @access private More...
 

Data Fields

 $INI_FILE_NAME = ""
 
 $ERROR = ""
 
 $GROUPS = array()
 
 $CURRENT_GROUP = ""
 

Detailed Description

INIFile Parser.

Early access in init proceess! Avoid further dependencies like logging or other services

Description:

A Simpe Ini File Implementation to keep settings in a simple file instead of in a DB Based upon class.INIfile.php by Mircho Mirev mirch.nosp@m.o@ma.nosp@m.cropo.nosp@m.int..nosp@m.com

Usage Examples: $ini = new IniFile("./ini.ini"); Read entire group in an associative array $grp = $ini->read_group("MAIN"); //prints the variables in the group if ($grp) for(reset($grp); $key=key($grp); next($grp)) { echo "GROUP ".$key."=".$grp[$key]."<br>"; } //set a variable to a value $ini->setVariable("NEW","USER","JOHN"); //Save the file $ini->save_data();

Author
Mircho Mirev mirch.nosp@m.o@ma.nosp@m.cropo.nosp@m.int..nosp@m.com
Peter Gabriel peter.nosp@m.@gab.nosp@m.riel-.nosp@m.onli.nosp@m.ne.ne.nosp@m.t
Version
$Id$

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

Member Function Documentation

◆ fixIniFile()

ilIniFile::fixIniFile ( )

Fix ini file (make it compatible for PHP 5.3)

Definition at line 144 of file class.ilIniFile.php.

145 {
146 // first read content
147 $lines = array();
148 $fp = @fopen($this->INI_FILE_NAME,"r");
149 while (!feof($fp))
150 {
151 $l = fgets($fp, 4096);
152 $skip = false;
153 if ((substr($l, 0, 2) == "/*" && $starttag) ||
154 substr($l, 0, 5) == "*/ ?>")
155 {
156 $skip = true;
157 }
158 $starttag = false;
159 if (substr($l, 0, 5) == "<?php")
160 {
161 $l = "; <?php exit; ?>";
162 $starttag = true;
163 }
164 if (!$skip)
165 {
166 $l = str_replace("\n", "", $l);
167 $l = str_replace("\r", "", $l);
168 $lines[] = $l;
169 }
170 }
171 fclose($fp);
172
173 // now write it back
174 $fp = @fopen($this->INI_FILE_NAME,"w");
175
176 if (!empty($fp))
177 {
178 foreach ($lines as $l)
179 {
180 fwrite($fp, $l."\r\n");
181 }
182 }
183 fclose($fp);
184
185 }
global $l
Definition: afr.php:30

References $l.

Referenced by parse().

+ Here is the caller graph for this function:

◆ ilIniFile()

ilIniFile::ilIniFile (   $a_ini_file_name)

Constructor @access public.

Parameters
stringname of file to be parsed
Returns
boolean

Definition at line 73 of file class.ilIniFile.php.

74 {
75 //check if a filename is given
76 if (empty($a_ini_file_name))
77 {
78 $this->error("no_file_given");
79 return false;
80 }
81
82 $this->INI_FILE_NAME = $a_ini_file_name;
83 return true;
84 }
error($a_errmsg)
set error message @access public

References error().

+ Here is the call graph for this function:

◆ parse()

ilIniFile::parse ( )

load and parse an inifile @access private

Returns
boolean

Definition at line 116 of file class.ilIniFile.php.

117 {
118 //use php4 function parse_ini_file
119 $this->GROUPS = @parse_ini_file($this->INI_FILE_NAME, true);
120
121 //check if groups are filled
122 if ($this->GROUPS == false)
123 {
124 // second try
125 $this->fixIniFile();
126
127 $this->GROUPS = @parse_ini_file($this->INI_FILE_NAME, true);
128 if ($this->GROUPS == false)
129 {
130 $this->error("file_not_accessible");
131 return false;
132 }
133 }
134 //set current group
135 $temp = array_keys($this->GROUPS);
136 $this->CURRENT_GROUP = $temp[count($temp)-1];
137 return true;
138
139 }
fixIniFile()
Fix ini file (make it compatible for PHP 5.3)

References error(), and fixIniFile().

Referenced by read().

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

◆ parse_data()

ilIniFile::parse_data (   $a_data)

parse data @access private

Parameters
array

Definition at line 192 of file class.ilIniFile.php.

193 {
194 if (ereg("\[([[:alnum:]]+)\]",$a_data,$out))
195 {
196 $this->CURRENT_GROUP= trim($out[1]);
197 }
198 elseif (!empty($a_data))
199 {
200 $split_data = split("=", $a_data);
201 $this->GROUPS[$this->CURRENT_GROUP][trim($split_data[0])]=trim($split_data[1]);
202 }
203 }

References $CURRENT_GROUP, and $out.

◆ read()

ilIniFile::read ( )

read from ini file @access public

Returns
boolean

Definition at line 91 of file class.ilIniFile.php.

92 {
93 //check if file exists
94 if (!file_exists($this->INI_FILE_NAME))
95 {
96 $this->error("file_does_not_exist");
97 return false;
98 }
99 else
100 {
101 //parse the file
102 if ($this->parse() == false)
103 {
104 return false;
105 }
106 }
107
108 return true;
109 }
parse()
load and parse an inifile @access private

References error(), and parse().

+ Here is the call graph for this function:

◆ setContent()

ilIniFile::setContent (   $a_data)

DESCRIPTION MISSING @access public.

Parameters
string
Returns
boolean true

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

212 {
213 $this->GROUPS = $a_data;
214 return true;
215 }

◆ write()

ilIniFile::write ( )

save ini-file-data to filesystem @access private

Returns
boolean

Definition at line 222 of file class.ilIniFile.php.

References $res, $result, error(), readGroup(), and readGroups().

Referenced by ilGlobalCacheSettings\writeToIniFile().

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

Field Documentation

◆ $CURRENT_GROUP

ilIniFile::$CURRENT_GROUP = ""

Definition at line 65 of file class.ilIniFile.php.

Referenced by parse_data().

◆ $ERROR

ilIniFile::$ERROR = ""

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

Referenced by getError().

◆ $GROUPS

ilIniFile::$GROUPS = array()

Definition at line 58 of file class.ilIniFile.php.

◆ $INI_FILE_NAME

ilIniFile::$INI_FILE_NAME = ""

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


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