ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilIniFile Class Reference

INIFile Parser. More...

+ Collaboration diagram for ilIniFile:

Public Member Functions

 ilIniFile ($a_ini_file_name)
 Constructor public.
 read ()
 read from ini file public
 parse ()
 load and parse an inifile private
 parse_data ($a_data)
 parse data private
 setContent ($a_data)
 DESCRIPTION MISSING public.
 write ()
 save ini-file-data to filesystem private
 show ()
 returns the content of IniFile public
 getGroupCount ()
 returns number of groups public
 readGroups ()
 returns an array with the names of all the groups public
 groupExists ($a_group_name)
 checks if a group exists public
 readGroup ($a_group_name)
 returns an associative array of the variables in one group public
 addGroup ($a_group_name)
 adds a new group public
 removeGroup ($a_group_name)
 removes a group public
 variableExists ($a_group, $a_var_name)
 returns if a variable exists or not public
 readVariable ($a_group, $a_var_name)
 reads a single variable from a group public
 setVariable ($a_group_name, $a_var_name, $a_var_value)
 sets a variable in a group public
 error ($a_errmsg)
 set error message public
 getError ()
 returns error public

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:
class.ilIniFile.php 22099 2009-10-13 13:18:42Z akill

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

Member Function Documentation

ilIniFile::addGroup (   $a_group_name)

adds a new group public

Parameters
stringgroup name
Returns
boolean

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

References error(), and groupExists().

{
if ($this->groupExists($a_group_name))
{
$this->error("Group '".$a_group_name."' exists");
return false;
}
$this->GROUPS[$a_group_name] = array();
return true;
}

+ Here is the call graph for this function:

ilIniFile::error (   $a_errmsg)

set error message public

Parameters
string

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

Referenced by addGroup(), ilIniFile(), parse(), read(), readGroup(), readVariable(), removeGroup(), setVariable(), and write().

{
$this->ERROR = $a_errmsg;
return true;
}

+ Here is the caller graph for this function:

ilIniFile::getError ( )

returns error public

Returns
string

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

References $ERROR.

{
return $this->ERROR;
}
ilIniFile::getGroupCount ( )

returns number of groups public

Returns
integer

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

{
return count($this->GROUPS);
}
ilIniFile::groupExists (   $a_group_name)

checks if a group exists public

Parameters
stringgroup name
Returns
boolean

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

Referenced by addGroup(), readGroup(), removeGroup(), and setVariable().

{
if (!isset($this->GROUPS[$a_group_name]))
{
return false;
}
return true;
}

+ Here is the caller graph for this function:

ilIniFile::ilIniFile (   $a_ini_file_name)

Constructor public.

Parameters
stringname of file to be parsed
Returns
boolean

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

References error().

{
//check if a filename is given
if (empty($a_ini_file_name))
{
$this->error("no_file_given");
return false;
}
$this->INI_FILE_NAME = $a_ini_file_name;
return true;
}

+ Here is the call graph for this function:

ilIniFile::parse ( )

load and parse an inifile private

Returns
boolean

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

References error().

Referenced by read().

{
//use php4 function parse_ini_file
$this->GROUPS = parse_ini_file($this->INI_FILE_NAME, true);
//check if groups are filled
if ($this->GROUPS == false)
{
$this->error("file_not_accessible");
return false;
}
//set current group
$temp = array_keys($this->GROUPS);
$this->CURRENT_GROUP = $temp[count($temp)-1];
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilIniFile::parse_data (   $a_data)

parse data private

Parameters
array

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

References $CURRENT_GROUP, and $out.

{
if (ereg("\[([[:alnum:]]+)\]",$a_data,$out))
{
$this->CURRENT_GROUP= trim($out[1]);
}
elseif (!empty($a_data))
{
$split_data = split("=", $a_data);
$this->GROUPS[$this->CURRENT_GROUP][trim($split_data[0])]=trim($split_data[1]);
}
}
ilIniFile::read ( )

read from ini file public

Returns
boolean

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

References error(), and parse().

{
//check if file exists
if (!file_exists($this->INI_FILE_NAME))
{
$this->error("file_does_not_exist");
return false;
}
else
{
//parse the file
if ($this->parse() == false)
{
return false;
}
}
return true;
}

+ Here is the call graph for this function:

ilIniFile::readGroup (   $a_group_name)

returns an associative array of the variables in one group public

Parameters
stringgroup name
Returns
mixed return array of values or boolean 'false' on failure

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

References error(), and groupExists().

Referenced by show(), and write().

{
if (!$this->groupExists($a_group_name))
{
$this->error("Group '".$a_group_name."' does not exist");
return false;
}
return $this->GROUPS[$a_group_name];
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilIniFile::readGroups ( )

returns an array with the names of all the groups public

Returns
array groups

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

Referenced by show(), and write().

{
$groups = array();
for (reset($this->GROUPS);$key=key($this->GROUPS);next($this->GROUPS))
{
$groups[]=$key;
}
return $groups;
}

+ Here is the caller graph for this function:

ilIniFile::readVariable (   $a_group,
  $a_var_name 
)

reads a single variable from a group public

Parameters
stringgroup name
stringvalue
Returns
mixed return value string or boolean 'false' on failure

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

References error().

{
if (!isset($this->GROUPS[$a_group][$a_var_name]))
{
$this->error("'".$a_var_name."' does not exist in '".$a_group."'");
return false;
}
return trim($this->GROUPS[$a_group][$a_var_name]);
}

+ Here is the call graph for this function:

ilIniFile::removeGroup (   $a_group_name)

removes a group public

Parameters
stringgroup name
Returns
boolean

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

References error(), and groupExists().

{
if (!$this->groupExists($a_group_name))
{
$this->error("Group '".$a_group_name."' does not exist");
return false;
}
unset($this->GROUPS[$a_group_name]);
return true;
}

+ Here is the call graph for this function:

ilIniFile::setContent (   $a_data)

DESCRIPTION MISSING public.

Parameters
string
Returns
boolean true

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

{
$this->GROUPS = $a_data;
return true;
}
ilIniFile::setVariable (   $a_group_name,
  $a_var_name,
  $a_var_value 
)

sets a variable in a group public

Parameters
string
string
string
Returns
boolean

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

References error(), and groupExists().

{
if (!$this->groupExists($a_group_name))
{
$this->error("Group '".$a_group_name."' does not exist");
return false;
}
$this->GROUPS[$a_group_name][$a_var_name] = $a_var_value;
return true;
}

+ Here is the call graph for this function:

ilIniFile::show ( )

returns the content of IniFile public

Returns
string content

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

References readGroup(), and readGroups().

{
$groups = $this->readGroups();
$group_cnt = count($groups);
//clear content
$content = "";
// go through all groups
for ($i=0; $i<$group_cnt; $i++)
{
$group_name = $groups[$i];
//prevent empty line at beginning of ini-file
if ($i==0)
{
$content = sprintf("[%s]\n",$group_name);
}
else
{
$content .= sprintf("\n[%s]\n",$group_name);
}
$group = $this->readGroup($group_name);
//go through group an display all variables
for (reset($group); $key=key($group);next($group))
{
$content .= sprintf("%s = %s\n",$key,$group[$key]);
}
}
return $content;
}

+ Here is the call graph for this function:

ilIniFile::variableExists (   $a_group,
  $a_var_name 
)

returns if a variable exists or not public

Parameters
stringgroup name
stringvalue
Returns
mixed return true if value exists or false

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

{
return isset($this->GROUPS[$a_group][$a_var_name]);
}
ilIniFile::write ( )

save ini-file-data to filesystem private

Returns
boolean

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

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

{
$fp = @fopen($this->INI_FILE_NAME,"w");
if (empty($fp))
{
$this->error("Cannot create file $this->INI_FILE_NAME");
return false;
}
//write php tags (security issue)
$result = fwrite($fp, "; <?php exit; ?>\r\n");
$groups = $this->readGroups();
$group_cnt = count($groups);
for ($i=0; $i<$group_cnt; $i++)
{
$group_name = $groups[$i];
//prevent empty line at beginning of ini-file
if ($i==0)
{
$res = sprintf("[%s]\r\n",$group_name);
}
else
{
$res = sprintf("\r\n[%s]\r\n",$group_name);
}
$result = fwrite($fp, $res);
$group = $this->readGroup($group_name);
for (reset($group); $key=key($group);next($group))
{
$res = sprintf("%s = %s\r\n",$key,"\"".$group[$key]."\"");
$result = fwrite($fp,$res);
}
}
fclose($fp);
return true;
}

+ Here is the call graph for this function:

Field Documentation

ilIniFile::$CURRENT_GROUP = ""

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

Referenced by parse_data().

ilIniFile::$ERROR = ""

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

Referenced by getError().

ilIniFile::$GROUPS = array()

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

ilIniFile::$INI_FILE_NAME = ""

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


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