IniService (since version 2.0)
Type Service
Constants
string PROFILE_PREFIX = " INIS. "
The profile prefix which is added to the profile name.
Methods
Description
The ini service handles ini files with the posibility to create profiles for storage of configuration data.
You can read, insert or delete keys or sections from the loaded ini file.
This service can also create an bundle of global constants with the prefix CONST: in the section name.
This service uses the ProfileService to handle als created profiles.
You can read, insert or delete keys or sections from the loaded ini file.
This service can also create an bundle of global constants with the prefix CONST: in the section name.
This service uses the ProfileService to handle als created profiles.
Examples
Ini file sample.ini:
;<?php exit(); ?>
[SECTION_1]
name = tom
age = 20
[SECTION_2]
name = mike
age = 21
[CONST:PATHS]
SAMPLES = "/root/samples/"
CONFIG = "/root/config/"
;<?php exit(); ?>
[SECTION_1]
name = tom
age = 20
[SECTION_2]
name = mike
age = 21
[CONST:PATHS]
SAMPLES = "/root/samples/"
CONFIG = "/root/config/"
<?php
// load ini file from filesystem
// constants will be auto defined if they do not exist
IniService::CreateProfile('IniSample', '/path/to/sample.ini');
// active the created profile
IniService::Begin('IniSample');
echo(PATHS_SAMPLES);
$Section = IniService::GetSection('SECTION_1');
// retrieve name and age of SECTION_1
echo($Section->name);
echo($Section->age);
// add new section and values to profile
IniService::AddSection
(
'SECTION_3',
array
(
'key_1' => 'value_1',
'key_2' => 'value_2',
'key_3' => 'value_3'
)
);
// add an key to the SECTION_1
IniService::AddSectionKey('SECTION_1', 'city', 'NewYork');
// save changed ini file
IniService::Save();
// deactivate the ini profile
IniService:End();
?>
Output:
/root/samples/
tom
20
// load ini file from filesystem
// constants will be auto defined if they do not exist
IniService::CreateProfile('IniSample', '/path/to/sample.ini');
// active the created profile
IniService::Begin('IniSample');
echo(PATHS_SAMPLES);
$Section = IniService::GetSection('SECTION_1');
// retrieve name and age of SECTION_1
echo($Section->name);
echo($Section->age);
// add new section and values to profile
IniService::AddSection
(
'SECTION_3',
array
(
'key_1' => 'value_1',
'key_2' => 'value_2',
'key_3' => 'value_3'
)
);
// add an key to the SECTION_1
IniService::AddSectionKey('SECTION_1', 'city', 'NewYork');
// save changed ini file
IniService::Save();
// deactivate the ini profile
IniService:End();
?>
Output:
/root/samples/
tom
20
Last change 10/13/2009