Public Member Functions | Data Fields

ilIniFile Class Reference

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
 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

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


Member Function Documentation

ilIniFile::addGroup ( a_group_name  ) 

adds a new group public

Parameters:
string group name
Returns:
boolean

Definition at line 338 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 411 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 423 of file class.ilIniFile.php.

        {
                return $this->ERROR;
        }

ilIniFile::getGroupCount (  ) 

returns number of groups public

Returns:
integer

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

        {
                return count($this->GROUPS);
        }

ilIniFile::groupExists ( a_group_name  ) 

checks if a group exists public

Parameters:
string group name
Returns:
boolean

Definition at line 305 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:
string name of file to be parsed
Returns:
boolean

Definition at line 91 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 134 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 156 of file class.ilIniFile.php.

        {
                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 109 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:
string group name
Returns:
mixed return array of values or boolean 'false' on failure

Definition at line 321 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 287 of file class.ilIniFile.php.

References $key.

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:
string group name
string value
Returns:
mixed return value string or boolean 'false' on failure

Definition at line 375 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:
string group name
Returns:
boolean

Definition at line 356 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 175 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 394 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 238 of file class.ilIniFile.php.

References $key, 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::write (  ) 

save ini-file-data to filesystem private

Returns:
boolean

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

References $key, $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 /*\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);
                        }
                }
                
                //write php tags (security issue)
                $result = fwrite($fp, "*/ ?>");
                
                fclose($fp);

                return true;
        }

Here is the call graph for this function:


Field Documentation

ilIniFile::$CURRENT_GROUP = ""

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

ilIniFile::$ERROR = ""

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

ilIniFile::$GROUPS = array()

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

ilIniFile::$INI_FILE_NAME = ""

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


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