utility class to modify an ini file by preserving comments, whitespace.
. It follows same behaviors of parse_ini_file, except when there are quotes inside values. it doesn't support quotes inside values, because parse_ini_file is totally bugged, depending cases.
| package |
jelix |
|---|---|
| subpackage |
utils |
| since | 1.1 |
__construct(string $filename)
| Throws |
|
|---|
stringthe file to load
generateIni()
getFileName() : string
| since | 1.2 |
|---|---|
stringthe file name
getIniValue( $value)
getSectionList() : array
| since | 1.2 |
|---|---|
array
getValue(string $name, string $section, integer $key = null) : mixed
stringthe name of the option to retrieve
stringthe section where the option is. 0 is the global section
integerfor option which is an item of array, the key in the array
mixedthe value
getValues(string $section) : array
stringthe section from wich we want values. 0 is the global section
arraythe list of values, $key=>$value
import(\jIniFileModifier $ini, string $sectionPrefix = '', string $separator = '_')
If a section prefix is given, all section of the given ini file will be renamed with the prefix plus "_". The global (unamed) section will be the section named with the value of prefix. If the section prefix is not given, the existing sections and given section with the same name will be merged.
| since | 1.2 |
|---|---|
stringthe prefix to add to the section prefix
stringthe separator to add between the prefix and the old name of the section
isModified() : boolean
| since | 1.2 |
|---|---|
boolean
isSection( $name)
| since | 1.2 |
|---|---|
mergeSection( $sectionSource, $sectionTarget) : boolean
booleantrue if the merge is a success
mergeValues( $values, $sectionTarget)
parse( $lines)
removeValue(string $name, string $section, integer $key = null, $removePreviousComment = true)
| since | 1.2 |
|---|---|
stringthe name of the option to remove, or null to remove an entire section
stringthe section where to remove the value, or the section to remove
integerfor option which is an item of array, the key in the array
renameSection( $oldName, $newName)
renameValue( $name, $newName, $section)
save( $chmod = null)
saveAs(string $filename)
stringthe name of the file
setValue(string $name, string $value, string $section, integer $key = null)
stringthe name of the option to modify
stringthe new value
stringthe section where to set the item. 0 is the global section
integerfor option which is an item of array, the key in the array. '' to just add a value in the array
setValues( $values, string $section)
stringthe section where to set the item. 0 is the global section
TK_WS
| const |
integer token type for whitespaces |
|---|---|
TK_COMMENT
| const |
integer token type for a comment |
|---|---|
TK_SECTION
| const |
integer token type for a section header |
|---|---|
TK_VALUE
| const |
integer token type for a simple value |
|---|---|
TK_ARR_VALUE
| const |
integer token type for a value of an array item |
|---|---|
content : array
each value of the items is an array of tokens. A token is an array with some values. first value is the token type (see TK_* constants), and other values depends of the token type:
| var |
|---|
array
filename : string
| var |
the filename of the ini file |
|---|
string
modified : boolean
| var |
true if the content has been modified |
|---|
boolean