View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Config_Writer
{zone-data}

{zone-data:proposer-list}
[Ben Scholzen|mailto:mail@dasprids.de]
{zone-data}

{zone-data:liaison}
Ralph Schindler
{zone-data}

{zone-data:revision}
1.0 - 1 October 2008: Initial Draft.
1.1 - 1 October 2008: Refactored proposal to use Zend_Config only as sources.
{zone-data}

{zone-data:overview}
Zend_Config_Writer is an addition to Zend_Config to write config objects back to files. It can take any Zend_Config object and save it with one of the adapters. Slight additions are required in Zend_Config for this.
{zone-data}

{zone-data:references}
* [Zend_Config|http://framework.zend.com/manual/en/zend.config.html]
{zone-data}

{zone-data:requirements}
* This component *will* be able to create new config files.
* This component *will* be able to write INI as well as XML config files
* This component *will* support (extending) sections
* This component *will* output the data in a generic format
* This component *will not* preserve formatting or comments in existing config files when rewriting them
{zone-data}

{zone-data:dependencies}
* Zend_Config
* Zend_Config_Xml
* Zend_Config_Ini
* Zend_Config_Exception
{zone-data}

{zone-data:operation}
First an instance of Zend_Config is created. Then modifications are directly done on this instance. After that an instance of Zend_Config_Writer_Interface is created. Then the modifications can be saved by calling Zend_Config_Writer_Interface::write();
{zone-data}

{zone-data:milestones}
* Milestone 1: [DONE] Finishing proposal
* Milestone 2: [DONE] Collecting community comments
* Milestone 3: [DONE] Approval by Zend
* Milestone 4: [DONE] Prototype finished and checked into SVN
* Milestone 5: [DONE] Unit tests exist, work, and are checked into SVN.
* Milestone 6: [DONE] Initial documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_Config_Writer
* Zend_Config_Writer_Exception
* Zend_Config_Writer_Interface
* Zend_Config_Writer_Xml
* Zend_Config_Writer_Ini
{zone-data}

{zone-data:use-cases}
||UC-01||
Creating a new config file

{code}
$config = new Zend_Config();
$config->createSection('foo');
$config->foo->firstgroup = array();
$config->foo->firstgroup->firstValue = 1;
$config->foo->firstgroup->secondValue = 2;

$config->createSection('bar', 'foo');
$config->bar->firstgroup = array();
$config->bar->firstgroup->secondValue = 5;

$writer = new Zend_Config_Writer_Xml();
$writer->write($config, 'my-config.xml');
{code}

||UC-02||
Updating an existing config file

{code}
$config = new Zend_Config_Xml('my-config.xml', null, array('allowModifications' => true, 'ignoreExtends' => true));
$config->foo->firstgroup->secondValue = 3;

$writer = new Zend_Config_Writer_Xml();
$writer->write($config, 'my-config.xml');
{code}

||UC-03||
Cloning a section and resetting extend parameter

{code}
$config = new Zend_Config_Xml('my-config.xml', null, array('allowModifications' => true, 'ignoreExtends' => true));
$config->newsection = clone $config->bar;
$config->newsection->setExtends('bar');

$writer = new Zend_Config_Writer_Xml();
$writer->write($config, 'my-config.xml');
{code}

||UC-04||
Converting an INI to an XML config file

{code}
$config = new Zend_Config_Ini('my-config.ini', null, array('allowModifications' => true, 'ignoreExtends' => true));
$writer = new Zend_Config_Writer_Xml();
$writer->write($config, 'my-config.xml');
{code}
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Config_Writer_Exception extends Zend_Config_Exception {}

class Zend_Config_Writer {
public function __construct($adapter, $filename = null);

public function save();
}

interface Zend_Config_Writer_Interface {
public function write(Zend_Config $config, $filename);
}

class Zend_Config_Writer_Ini implements Zend_Config_Writer_Interface {
public function write(Zend_Config $config, $filename);
}

class Zend_Config_Writer_Xml implements Zend_Config_Writer_Interface {
public function write(Zend_Config $config, $filename);
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>