View Source

<ac:macro ac:name="info"><ac:parameter ac:name="title">Zend_Config_Json</ac:parameter></ac:macro>
<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_Json
{zone-data}

{zone-data:proposer-list}
[Sudheer Satyanarayana|mailto:sudheer.s@sudheer.net]
{zone-data}

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

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

{zone-data:overview}
Zend_Config_Json reads a text configuration file whose contents are in JSON format.
{zone-data}

{zone-data:references}
* [Wikipedia page |http://en.wikipedia.org/wiki/Json]
* [json.org|http://www.json.org/]
{zone-data}

{zone-data:requirements}
* This component *will* read a configuration file whose contents are in JSON format
* The component *will* support configuration sections
* This component *will* will not save information to the storage media. Zend_Config_Writer_Json will be proposed once we freeze the specification of this component.
{zone-data}

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

{zone-data:operation}
This component works much like Zend_Config_Ini and Zend_Config_Xml offering another data format support - JSON.
{zone-data}

{zone-data:milestones}
* Milestone 1: Complete writing this proposal
* Milestone 2: Working prototype checked into the incubator
* Milestone 4: Unit tests exist, work, and are checked into SVN.
* Milestone 5: Initial documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_Config_Json
* Zend_Config_Writer_Json
{zone-data}

{zone-data:use-cases}
||UC-01||
application/configs/database.json

{code:json}
production: {
webhost: "www.example.com"
database: {
adapter: "pdo_mysql"
params: {
host: "db.example.com"
username: "dbuser"
password: "secret"
dbname: "mydatabase"
}
}
}
staging: {
configOptions: {
extends: "production"
}
webhost: "staging.example.com"
}
{code}


The wiki doesn't seem to allow me to print curly braces. For now, please assume the contents of the file are enclosed within curly braces.

I have attached the sample JSON configuration file to this proposal.

In a PHP script
{code:php}
$config = new Zend_Config_Json('application/configs/database.json', 'staging');
echo $config->database->params->webhost; // prints "staging.example.com"
echo $config->database->params->dbname; // prints "mydatabase"
{code}

{zone-data}

{zone-data:skeletons}
{code}
class Zend_Config_Json extends Zend_Config {}
class Zend_Config_Writer_Json extends Zend_Config_Writer {}

{code}
{zone-data}

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