ezcConfigurationFileWriter class provides the functionality for writing file based configuration formats.
This class implements most of the interface of ezcConfigurationWriter and makes it easier to work on file based configuration. All methods except save() are implemented by this class so a subclass only needs to handle the actual serialization.
Source for this file: /Configuration/src/file_writer.php
ezcConfigurationWriter | --ezcConfigurationFileWriter
Version: | //autogen// |
Child Class | Description |
---|---|
ezcConfigurationArrayWriter | This class provides functionality for writing ezcConfiguration object into files containing PHP arrays. |
ezcConfigurationIniWriter | This class provides functionality for writing ezcConfiguration objects into INI files. |
protected bool |
$config
= false
Contains the configuration object to write with the save() method. |
protected string |
$location
= ''
The current location of the config, this is either the path on the filesystem or a PHP stream prefix. |
protected string |
$name
= ''
The base name of the configuration file, the suffix will be appended to this to find the real filename. |
protected array |
$options
= array()
Current options for the writer. See the specific writer to see which options it supports. |
protected string |
$path
= ''
The path to the file which will contain the serialized configuration data. |
protected int |
$permissions
= 0666
Contains the file permissions for the file to write the INI settings to. |
protected bool |
$useComments
= true
Controls whether comments are written to the INI file or not. |
public ezcConfigurationFileWriter |
__construct(
[ $path
= null] , [ $config
= null] , [ $permissions
= 0666] )
Constructs the writer and initializes it with the file to write. |
protected void |
closeFile(
$fp
)
Closes a file pointed to by $fp and sets file permissions. |
public string |
getLocation(
)
Return the current location string. |
public int |
getName(
)
Return the current name for the configuration to be written. |
public array |
getOptions(
)
Returns the current options for the writer. |
public void |
init(
$location
, $name
, $config
, [ $options
= array()] )
Initializes the writer with a $location and a $name. |
protected resource |
openFile(
)
Opens a file for writing. |
protected void |
parseLocationPath(
$path
, $suffix
)
Parses a the path $path and sets the location and name properties on this object. |
public void |
save(
)
Saves the current config object. |
public void |
setConfig(
$config
)
Sets the configuration object that will be used for the next call to save(). |
public void |
setOptions(
$configurationData
)
Sets the options $configurationData. |
From ezcConfigurationWriter | |
---|---|
public abstract string |
ezcConfigurationWriter::getLocation()
Returns the current location string. |
public abstract string |
ezcConfigurationWriter::getName()
Returns the current name for the configuration to be written. |
public abstract array |
ezcConfigurationWriter::getOptions()
Returns the current options for the writer. |
protected abstract string |
ezcConfigurationWriter::getSuffix()
Returns the suffix used in the storage filename. |
public abstract void |
ezcConfigurationWriter::init()
Initializes the writer with a $location and a $name. |
public abstract void |
ezcConfigurationWriter::save()
Saves the current config object. |
public abstract void |
ezcConfigurationWriter::setConfig()
Sets the configuration object that will be used for the next call to save(). |
public abstract void |
ezcConfigurationWriter::setOptions()
Sets the options for the writer. |
Constructs the writer and initializes it with the file to write.
After construction call save() to store the INI file to disk.
Name | Type | Description |
---|---|---|
$path |
string | The relative or absolute path to where the configuration should be written to. Using PHP streams is also possible, e.g. compress.gz://site.ini.gz |
$config |
ezcConfiguration | The configuration object which should be stored in an INI file. |
$permissions |
int | The file permission to use on the newly created file, it uses the same values as chmod(). |
Closes a file pointed to by $fp and sets file permissions.
This method closes a file with the file pointer that was passed. After closing the file the permissions are set as configured with the "permissions" option.
Name | Type | Description |
---|---|---|
$fp |
resource |
Return the current location string.
Method | Description |
---|---|
ezcConfigurationWriter::getLocation() |
Returns the current location string. |
Return the current name for the configuration to be written.
Method | Description |
---|---|
ezcConfigurationWriter::getName() |
Returns the current name for the configuration to be written. |
Returns the current options for the writer.
Method | Description |
---|---|
ezcConfigurationWriter::getOptions() |
Returns the current options for the writer. |
Initializes the writer with a $location and a $name.
These values determine where the configuration will be serialized.
The location string can be used to determine the directory location for an INI file.
The name parameter can be the basename for the INI file, so a value of 'site' would create a file with name 'site.ini'.
Name | Type | Description |
---|---|---|
$location |
string | The main placement for the configuration. It is up to the specific writer to interpret this value. |
$name |
string | The name for the configuration. It is up to the specific writer to interpret this value. For a file writer it could be the basename for the INI file, so a value of 'site' would create a file with name 'site.ini'. |
$config |
ezcConfiguration | The current configuration object which should be serialized by the current writer. |
$options |
array | An associative array of options for the writer. Which options to use is determined by the specific writer class. |
Method | Description |
---|---|
ezcConfigurationWriter::init() |
Initializes the writer with a $location and a $name. |
Opens a file for writing.
This method opens a file for writing and checks whether it was successfully opened.
Type | Description |
---|---|
ezcConfigurationWriteFailedException |
if it was not possible to write to the file. |
Parses a the path $path and sets the location and name properties on this object.
The file is checked if it contains the correct $suffix.
ezcConfigurationFileReader::parseLocationPath() has the same code. It is duplicated to prevent complex OO hacks.
Name | Type | Description |
---|---|---|
$path |
string | |
$suffix |
string |
Type | Description |
---|---|
ezcConfigurationInvalidSuffixExceptionif |
the configuration file has the wrong suffix. |
Saves the current config object.
Saves the current configuration object to a place which can later be retrieved with a ezcConfigurationReader.
Type | Description |
---|---|
ezcConfigurationNoConfigObjectException |
if there is not config object set to write. |
ezcConfigurationInvalidSuffixExceptionif |
the configuration file has the wrong suffix. |
ezcConfigurationWriteFailureException |
if the configuration could not be stored in the given location. |
Method | Description |
---|---|
ezcConfigurationWriter::save() |
Saves the current config object. |
Sets the configuration object that will be used for the next call to save().
Pass false if you wish to remove the current configuration object.
Name | Type | Description |
---|---|---|
$config |
ezcConfiguration |
Method | Description |
---|---|
ezcConfigurationWriter::setConfig() |
Sets the configuration object that will be used for the next call to save(). |
Sets the options $configurationData.
The options are specified in a associative array in the form 'optionName' => value.
Name | Type | Description |
---|---|---|
$configurationData |
array(string=>mixed) |
Type | Description |
---|---|
ezcBaseSettingValueException |
if you specify a value out of range for a setting. |
ezcBaseSettingNotFoundException |
if you try to set a non existent setting. |
Method | Description |
---|---|
ezcConfigurationWriter::setOptions() |
Sets the options for the writer. |