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_Yaml
{zone-data}

{zone-data:proposer-list}
[Stas Malyshev|mailto:stas@zend.com]
{zone-data}

{zone-data:liaison}
TBD
{zone-data}

{zone-data:revision}
1.0 - 23 November 2009: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Config_Yaml implements YAML markup support for Zend_Config reading and writing.
{zone-data}

{zone-data:references}
* [YAML|http://yaml.org]
{zone-data}

{zone-data:requirements}
* This component *will* allow Zend_Config users to read and write YAML configuration files
* This component *will* allow to use pluggable YAML parser/generator, since there's no standard Zend_Yaml component for now.
* This component *will* support configuration sections.
* This component *will* support single inheritance of configuration sections.
{zone-data}

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

{zone-data:operation}
The component will allow to read and write configuration files in YAML format. Built-in parser will support only the simple subset of YAML, but external parsers (such as syck or spyc) can be plugged in for more complex formats.
{zone-data}

{zone-data:milestones}
* Milestone 1: \[DONE\] Create the spec for YAML support in Zend_Config
* Milestone 2: \[DONE\] Working code checked into the lab
* Milestone 3: \[DONE\] Parser unit tests checked into the lab
* Milestone 4: Writer unit tests checked into the lab
* Milestone 5: Proposal accepted
* Milestone 6: Documentation for the component exists
* Milestone 7: Code checked into the trunk
{zone-data}

{zone-data:class-list}
* Zend_Config_Yaml
* Zend_Config_Writer_Yaml
{zone-data}

{zone-data:use-cases}
{composition-setup}
{deck:id=Zend_Config}
{card:label=UC-01: simple config}
{code}
<?php
$config = new Zend_Config_Yaml('config.yaml');
{code}
{card}

{card:label=UC-02: using external parser}
{code}
<?php
$config = new Zend_Config_Yaml('config.yaml', null, array('yamlDecoder' => 'spyc_load'));
{code}
{card}

{card:label=UC-03: writing YAML confing}
{code}
<?php
$writer = new Zend_Config_Writer_Yaml(array('config' => $config, 'filename' => 'yconfig.yaml'));
{code}
{card}

{card:label=Simple YAML config file}
{code}
site_conf:
endpoint: http://mysite.com/service
application_id: MyApp
account_id: 12345
log: true
backend_conf:
address:
username:
password:
{code}
{card}

{card:label=More complex YAML config file}
{code}
all:
hostname: all
name: thisname
db:
host: 127.0.0.1
user: username
pass: password
name: live
one:
two:
three: multi
staging:
hostname: staging
db:
name: dbstaging
debug:
_extends: all
debug:
hostname: debug
debug: 1
values:
changed: 1
db:
name: dbdebug
special:
no:
null:
false:
_extends: all
other_staging:
only_in: otherStaging
db:
pass: anotherpwd
one:
two:
- 2a
- 2b
three:
four:
-
five: 5
- 4
-
five: 5
six:
seven:
-
eight: 1
nine: 1
-
eight: 2
nine: 2
-
eight: 3
nine: 3
{code}
{card}

{deck}
{zone-data}

{zone-data:skeletons}
{deck:id=Zend_Config classes}
{card:label=Zend_Config_Yaml}
{code}
class Zend_Config_Yaml extends Zend_Config
{
const EXTENDS_NAME = "_extends";
/**
* Whether to skip extends or not
*
* @var boolean
*/
protected $_skipExtends = false;

/**
* What to call when we need to decode some YAML?
*
* @var callable
*/
protected $yamlDecoder = array('Zend_Config_Yaml', 'decode');
/**
* Loads the section $section from the config file encoded as YAML
*
* Sections are defined as properties of the main object
*
* In order to extend another section, a section defines the "_extends"
* property having a value of the section name from which the extending
* section inherits values.
*
* Note that the keys in $section will override any keys of the same
* name in the sections that have been included via "_extends".
*
* @param string $yaml YAML file to process
* @param mixed $section Section to process
* @param boolean $options Whether modifiacations are allowed at runtime
*/
public function __construct($yaml, $section = null, $options = false) {}
/**
* Helper function to process each element in the section and handle
* the "_extends" inheritance attribute.
*
* @param array $data Data array to process
* @param string $section Section to process
* @param array $config Configuration which was parsed yet
* @throws Zend_Config_Exception When $section cannot be found
* @return array
*/
protected function _processExtends(array $data, $section, array $config = array()) {}
/**
* Very dumb YAML parser
*
* Until we have Zend_Yaml...
*
* @param string $yaml YAML source
* @return array Decoded data
*/
public static function decode($yaml) {}
}
{code}
{card}

{card:label=Zend_Config_Writer_Yaml}
{code}
class Zend_Config_Writer_Yaml extends Zend_Config_Writer_FileAbstract
{
/**
* What to call when we need to decode some YAML?
*
* @var callable
*/
protected $yamlEncoder = array('Zend_Config_Writer_Yaml', 'encode');
/**
* Render a Zend_Config into a YAML config string.
*
* @since 1.10
* @return string
*/
public function render(){}
/**
* Very dumb YAML encoder
*
* Until we have Zend_Yaml...
*
* @param array $data YAML data
* @return string
*/
public static function encode($data) {}
{code}
{card}
{deck}
{zone-data}

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