jIniFileModifier

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

Methods

load the given ini file

__construct(string $filename) 
Throws
\Exception

Arguments

$filename

string

the file to load

generateIni

generateIni() 

getFileName

getFileName() : string
since 1.2

Response

string

the file name

getIniValue

getIniValue( $value) 

Arguments

$value

return the list of section names

getSectionList() : array
since 1.2

Response

array

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

getValue(string $name, string $section, integer $key = null) : mixed

Arguments

$name

string

the name of the option to retrieve

$section

string

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

$key

integer

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

Response

mixed

the value

return all values of a section in the ini file.

getValues(string $section) : array

Arguments

$section

string

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

Response

array

the list of values, $key=>$value

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

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

Arguments

$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

says if the ini content has been modified

isModified() : boolean
since 1.2

Response

boolean

says if there is a section with the given name

isSection( $name) 
since 1.2

Arguments

$name

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

mergeSection( $sectionSource,  $sectionTarget) : boolean

Arguments

$sectionSource

$sectionTarget

Response

boolean

true if the merge is a success

mergeValues

mergeValues( $values,  $sectionTarget) 

Arguments

$values

$sectionTarget

parsed the lines of the ini file

parse( $lines) 

Arguments

$lines

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

removeValue(string $name, string $section, integer $key = null,  $removePreviousComment = true) 
since 1.2

Arguments

$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

integer

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

$removePreviousComment

rename a section

renameSection( $oldName,  $newName) 

Arguments

$oldName

$newName

rename a value

renameValue( $name,  $newName,  $section) 

Arguments

$name

$newName

$section

save the ini file

save( $chmod = null) 

Arguments

$chmod

save the content in an new ini file

saveAs(string $filename) 

Arguments

$filename

string

the name of the file

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

setValue(string $name, string $value, string $section, integer $key = null) 

Arguments

$name

string

the name of the option to modify

$value

string

the new value

$section

string

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

$key

integer

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

modify several options in the ini file.

setValues( $values, string $section) 

Arguments

$values

$section

string

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

Constants

TK_WS

TK_WS
const

integer token type for whitespaces

TK_COMMENT

TK_COMMENT
const

integer token type for a comment

TK_SECTION

TK_SECTION
const

integer token type for a section header

TK_VALUE

TK_VALUE
const

integer token type for a simple value

TK_ARR_VALUE

TK_ARR_VALUE
const

integer token type for a value of an array item

Properties

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.

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
var

Type(s)

array

the filename of the ini file

filename : string
var

the filename of the ini file

Type(s)

string

true if the content has been modified

modified : boolean
var

true if the content has been modified

Type(s)

boolean