ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilIniFile Class Reference

INIFile Parser. More...

+ Collaboration diagram for ilIniFile:

Public Member Functions

 __construct ($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...
 
 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.

Constructor & Destructor Documentation

◆ __construct()

ilIniFile::__construct (   $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 $this->error("no_file_given");
78 return false;
79 }
80
81 $this->INI_FILE_NAME = $a_ini_file_name;
82 return true;
83 }
error($a_errmsg)
set error message @access public

References error().

+ Here is the call graph for this function:

Member Function Documentation

◆ fixIniFile()

ilIniFile::fixIniFile ( )

Fix ini file (make it compatible for PHP 5.3)

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

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

Referenced by parse().

+ Here is the caller graph for this function:

◆ parse()

ilIniFile::parse ( )

load and parse an inifile @access private

Returns
boolean

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

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

◆ read()

ilIniFile::read ( )

read from ini file @access public

Returns
boolean

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

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

References error(), and parse().

+ Here is the call graph for this function:

◆ write()

ilIniFile::write ( )

save ini-file-data to filesystem @access private

Returns
boolean

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

References $i, $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.

◆ $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: