ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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.

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 34 of file class.ilIniFile.php.

Member Function Documentation

◆ fixIniFile()

ilIniFile::fixIniFile ( )

Fix ini file (make it compatible for PHP 5.3)

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

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

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 70 of file class.ilIniFile.php.

71 {
72 //check if a filename is given
73 if (empty($a_ini_file_name))
74 {
75 $this->error("no_file_given");
76 return false;
77 }
78
79 $this->INI_FILE_NAME = $a_ini_file_name;
80 return true;
81 }
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 113 of file class.ilIniFile.php.

114 {
115 //use php4 function parse_ini_file
116 $this->GROUPS = @parse_ini_file($this->INI_FILE_NAME, true);
117
118 //check if groups are filled
119 if ($this->GROUPS == false)
120 {
121 // second try
122 $this->fixIniFile();
123
124 $this->GROUPS = @parse_ini_file($this->INI_FILE_NAME, true);
125 if ($this->GROUPS == false)
126 {
127 $this->error("file_not_accessible");
128 return false;
129 }
130 }
131 //set current group
132 $temp = array_keys($this->GROUPS);
133 $this->CURRENT_GROUP = $temp[count($temp)-1];
134 return true;
135
136 }
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 189 of file class.ilIniFile.php.

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

References $CURRENT_GROUP, and $out.

◆ read()

ilIniFile::read ( )

read from ini file @access public

Returns
boolean

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

89 {
90 //check if file exists
91 if (!file_exists($this->INI_FILE_NAME))
92 {
93 $this->error("file_does_not_exist");
94 return false;
95 }
96 else
97 {
98 //parse the file
99 if ($this->parse() == false)
100 {
101 return false;
102 }
103 }
104
105 return true;
106 }
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 208 of file class.ilIniFile.php.

209 {
210 $this->GROUPS = $a_data;
211 return true;
212 }

◆ write()

ilIniFile::write ( )

save ini-file-data to filesystem @access private

Returns
boolean

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

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

+ Here is the call graph for this function:

Field Documentation

◆ $CURRENT_GROUP

ilIniFile::$CURRENT_GROUP = ""

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

Referenced by parse_data().

◆ $ERROR

ilIniFile::$ERROR = ""

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

Referenced by getError().

◆ $GROUPS

ilIniFile::$GROUPS = array()

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

◆ $INI_FILE_NAME

ilIniFile::$INI_FILE_NAME = ""

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


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