Configuration: ezcConfigurationFileWriter
[ ]
[ ]
[ ]
[ ]
[ ]
Class: ezcConfigurationFileWriter
|
ezcConfigurationFileWriter class provides the functionality for writing file based configuration formats. [
source]
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.
Parents
ezcConfigurationWriter
|
--ezcConfigurationFileWriter
Descendents
| Child Class |
Description |
| ezcConfigurationIniWriter |
This class provides functionality for writing ezcConfiguration objects into INI files.
|
| ezcConfigurationArrayWriter |
This class provides functionality for writing ezcConfiguration object into files containing PHP arrays.
|
Member Variables
|
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. |
|
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. |
Method Summary
|
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. |
Inherited Methods
From
ezcConfigurationWriter :
Methods
__construct
ezcConfigurationFileWriter __construct(
[string
$path = null], [
ezcConfiguration
$config = null], [int
$permissions = 0666] )
Constructs the writer and initializes it with the file to write.
After construction call save() to store the INI file to disk.
Parameters
| 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(). |
closeFile
void closeFile(
resource
$fp )
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.
Parameters
| Name |
Type |
Description |
$fp |
resource |
|
getLocation
string getLocation(
)
Return the current location string.
Redefinition of
getName
int getName(
)
Return the current name for the configuration to be written.
Redefinition of
getOptions
array getOptions(
)
Returns the current options for the writer.
Redefinition of
init
void init(
string
$location, string
$name,
ezcConfiguration
$config, [array
$options = array()] )
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'.
Parameters
| 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. |
Redefinition of
openFile
resource openFile(
)
Opens a file for writing.
This method opens a file for writing and checks whether it was successfully opened.
Throws
| Class | Description |
ezcConfigurationWriteFailedException |
if it was not possible to write to the file. |
parseLocationPath
void parseLocationPath(
string
$path, string
$suffix )
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.
Parameters
| Name |
Type |
Description |
$path |
string |
|
$suffix |
string |
|
Throws
| Class | Description |
ezcConfigurationInvalidSuffixExceptionif |
the configuration file has the wrong suffix. |
save
void save(
)
Saves the current config object.
Saves the current configuration object to a place which can later be retrieved with a ezcConfigurationReader.
Throws
| Class | 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. |
Redefinition of
setConfig
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.
Parameters
Redefinition of
setOptions
void setOptions(
array(string=>mixed)
$configurationData )
Sets the options $configurationData.
The options are specified in a associative array in the form 'optionName' => value.
Parameters
| Name |
Type |
Description |
$configurationData |
array(string=>mixed) |
|
Throws
| Class | Description |
ezcBaseSettingNotFoundException |
if you try to set a non existent setting. |
ezcBaseSettingValueException |
if you specify a value out of range for a setting. |
Redefinition of
Last updated: Mon, 17 Dec 2007