Jelix 1.6.40

jIniFileModifier
in package

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.

Tags
subpackage

utils

since
1.1

Table of Contents

TK_ARR_VALUE  = 4
TK_COMMENT  = 1
TK_SECTION  = 2
TK_VALUE  = 3
TK_WS  = 0
$content  : array<string|int, mixed>
each item of this array contains data for a section. the key of the item is the section name. There is a section with the key "0", and which contains data for options which are not in a section.
$filename  : string
$modified  : bool
__construct()  : mixed
load the given ini file
getFileName()  : string
getSectionList()  : array<string|int, mixed>
return the list of section names
getValue()  : mixed
return the value of an option in the ini file. If the option doesn't exist, it returns null.
getValues()  : array<string|int, mixed>
return all values of a section in the ini file.
import()  : mixed
import values of an ini file into the current ini content.
isModified()  : bool
says if the ini content has been modified
isSection()  : mixed
says if there is a section with the given name
mergeSection()  : bool
move values of a section into an other section and remove the section
removeSection()  : mixed
remove a section from the ini file.
removeValue()  : mixed
remove an option from the ini file. It can remove an entire section if you give an empty value as $name, and a $section name
renameSection()  : mixed
rename a section
renameValue()  : mixed
rename a value
save()  : mixed
save the ini file
saveAs()  : mixed
save the content in an new ini file
setValue()  : mixed
modify an option in the ini file. If the option doesn't exist, it is created.
setValues()  : mixed
modify several options in the ini file.
_compareNewValue()  : mixed
_setArrayValue()  : mixed
_setValue()  : mixed
convertValue()  : mixed
generateIni()  : mixed
getIniValue()  : mixed
mergeValues()  : mixed
parse()  : mixed
parsed the lines of the ini file

Constants

TK_ARR_VALUE

public mixed TK_ARR_VALUE = 4
Tags
const

integer token type for a value of an array item

Properties

$content

each item of this array contains data for a section. the key of the item is the section name. There is a section with the key "0", and which contains data for options which are not in a section.

protected array<string|int, mixed> $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:

  • TK_WS: content of whitespaces
  • TK_COMMENT: the comment
  • TK_SECTION: the section name
  • TK_VALUE: the name, and the value
  • TK_ARRAY_VALUE: the name, the value, and the key

Methods

__construct()

load the given ini file

public __construct(string $filename) : mixed
Parameters
$filename : string

the file to load

Tags
throws
Exception
Return values
mixed

getFileName()

public getFileName() : string
Tags
since
1.2
Return values
string

the file name

getSectionList()

return the list of section names

public getSectionList() : array<string|int, mixed>
Tags
since
1.2
Return values
array<string|int, mixed>

getValue()

return the value of an option in the ini file. If the option doesn't exist, it returns null.

public getValue(string $name, string $section[, int $key = null ]) : mixed
Parameters
$name : string

the name of the option to retrieve

$section : string

the section where the option is. 0 is the global section

$key : int = null

for option which is an item of array, the key in the array

Return values
mixed

the value

getValues()

return all values of a section in the ini file.

public getValues(string $section) : array<string|int, mixed>
Parameters
$section : string

the section from wich we want values. 0 is the global section

Return values
array<string|int, mixed>

the list of values, $key=>$value

import()

import values of an ini file into the current ini content.

public import(jIniFileModifier $ini[, string $sectionPrefix = '' ][, string $separator = '_' ]) : mixed

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.

Parameters
$ini : jIniFileModifier

an ini file modifier to merge with the current

$sectionPrefix : string = ''

the prefix to add to the section prefix

$separator : string = '_'

the separator to add between the prefix and the old name of the section

Tags
since
1.2
Return values
mixed

isModified()

says if the ini content has been modified

public isModified() : bool
Tags
since
1.2
Return values
bool

isSection()

says if there is a section with the given name

public isSection(mixed $name) : mixed
Parameters
$name : mixed
Tags
since
1.2
Return values
mixed

mergeSection()

move values of a section into an other section and remove the section

public mergeSection(mixed $sectionSource, mixed $sectionTarget) : bool
Parameters
$sectionSource : mixed
$sectionTarget : mixed
Return values
bool

true if the merge is a success

removeSection()

remove a section from the ini file.

public removeSection(string $section[, mixed $removePreviousComment = true ]) : mixed
Parameters
$section : string

the section where to remove the value, or the section to remove

$removePreviousComment : mixed = true
Tags
since
2.4.3
Return values
mixed

removeValue()

remove an option from the ini file. It can remove an entire section if you give an empty value as $name, and a $section name

public removeValue(string $name, string $section[, int $key = null ][, mixed $removePreviousComment = true ]) : mixed
Parameters
$name : string

the name of the option to remove, or null to remove an entire section

$section : string

the section where to remove the value, or the section to remove

$key : int = null

for option which is an item of array, the key in the array

$removePreviousComment : mixed = true
Tags
since
1.2
Return values
mixed

renameSection()

rename a section

public renameSection(mixed $oldName, mixed $newName) : mixed
Parameters
$oldName : mixed
$newName : mixed
Return values
mixed

renameValue()

rename a value

public renameValue(mixed $name, mixed $newName, mixed $section) : mixed
Parameters
$name : mixed
$newName : mixed
$section : mixed
Return values
mixed

save()

save the ini file

public save([mixed $chmod = null ]) : mixed
Parameters
$chmod : mixed = null
Return values
mixed

saveAs()

save the content in an new ini file

public saveAs(string $filename) : mixed
Parameters
$filename : string

the name of the file

Return values
mixed

setValue()

modify an option in the ini file. If the option doesn't exist, it is created.

public setValue(string $name, string|array<string|int, mixed> $value, string $section[, int $key = null ]) : mixed
Parameters
$name : string

the name of the option to modify

$value : string|array<string|int, mixed>

the new value

$section : string

the section where to set the item. 0 is the global section

$key : int = null

for option which is an item of array, the key in the array. '' to just add a value in the array

Return values
mixed

setValues()

modify several options in the ini file.

public setValues(mixed $values, string $section) : mixed
Parameters
$values : mixed
$section : string

the section where to set the item. 0 is the global section

Return values
mixed

_compareNewValue()

protected _compareNewValue(mixed $iniValue, mixed $newValue) : mixed
Parameters
$iniValue : mixed
$newValue : mixed
Return values
mixed

_setArrayValue()

protected _setArrayValue(mixed $name, mixed $value, mixed $section) : mixed
Parameters
$name : mixed
$value : mixed
$section : mixed
Return values
mixed

_setValue()

protected _setValue(mixed $name, mixed $value, mixed $section[, mixed $key = null ]) : mixed
Parameters
$name : mixed
$value : mixed
$section : mixed
$key : mixed = null
Return values
mixed

convertValue()

protected convertValue(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

getIniValue()

protected getIniValue(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

mergeValues()

protected mergeValues(mixed $values, mixed $sectionTarget) : mixed
Parameters
$values : mixed
$sectionTarget : mixed
Return values
mixed

parse()

parsed the lines of the ini file

protected parse(mixed $lines) : mixed
Parameters
$lines : mixed
Return values
mixed

Search results