## Apache Zeta Components Manual :: Docs For Class ezcConfigurationFileWriter

### Configuration::ezcConfigurationFileWriter

### Class ezcConfigurationFileWriter

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//

### Descendants

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.

### 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. 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.

### 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
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.

### 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:

Method | Description
--- | ---
`ezcConfigurationWriter::getLocation()` | Returns the current location string.

#### getName

int getName( )

Return the current name for the configuration to be written.

##### Redefinition of:

Method | Description
--- | ---
`ezcConfigurationWriter::getName()` | Returns the current name for the configuration to be written.

#### getOptions

array getOptions( )

Returns the current options for the writer.

##### Redefinition of:

Method | Description
--- | ---
`ezcConfigurationWriter::getOptions()` | Returns the current options for the writer.

#### 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:

Method | Description
--- | ---
`ezcConfigurationWriter::init()` | Initializes the writer with a $location and a $name.

#### openFile

resource openFile( )

Opens a file for writing.

This method opens a file for writing and checks whether it was successfully opened.

##### Exceptions:

Type | 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 |

##### Exceptions:

Type | 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.

##### Exceptions:

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.

##### Redefinition of:

Method | Description
--- | ---
`ezcConfigurationWriter::save()` | Saves the current config object.

#### setConfig

void setConfig( ezcConfiguration $config )

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:

Name | Type | Description
--- | --- | ---
`$config` | ezcConfiguration |

##### Redefinition of:

Method | Description
--- | ---
`ezcConfigurationWriter::setConfig()` | Sets the configuration object that will be used for the next call to save().

#### 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) |

##### Exceptions:

Type | Description
--- | ---
`ezcBaseSettingValueException` | if you specify a value out of range for a setting.
`ezcBaseSettingNotFoundException` | if you try to set a non existent setting.

##### Redefinition of:

Method | Description
--- | ---
`ezcConfigurationWriter::setOptions()` | Sets the options for the writer.

Documentation generated by phpDocumentor 1.4.3