Zend Framework: Zend_Config_Xml Attribute Support - Ben Scholzen Component Proposal
| Proposed Component Name | Zend_Config_Xml Attribute Support - Ben Scholzen |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Config_Xml Attribute Support - Ben Scholzen |
| Proposers | Ben Scholzen Zend Liaison - Ralph Schindler |
| Revision | 1.0 - 20 February 2008: Initial proposal. 1.1 - 20 February 2008: Prototype and unit tests finished. (wiki revision: 12) |
Table of Contents
1. Overview
This proposal will extend Zend_Config_Xml to be able to use node attributes. This will make config files not only more readable, but also easier to handle and quite smaller.
2. References
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will keep the compatibility with prior xml config files.
- This component will allow values given by parent nodes.
- This component will allow a short form of parameter values.
4. Dependencies on Other Framework Components
- Zend_Config
5. Theory of Operation
The Config is instantiated like before, and the usage nor the data structure will change in any way. Programmers just get the ability to write their configurations in a shorter way.
Parameters of a node can either be attribute values in a parent node (which may contain childs, but doesn't have to), or as sub-nodes of the parent. In this case, either the the classic style can be used (<key>value</key>) or one of the two new styles (<key value="value"/> or <param name="key" value="value"/>). To keep things backward compatible, a parameter with the key "extend" is not permitted in parent node attributes.
6. Milestones / Tasks
- Milestone 1: [DONE] Proposal finished
- Milestone 2: [DONE] Working prototype checked into http://zend.svn.dasprids.de
- Milestone 3: [DONE] Unit tests exist, work, and are checked into http://zend.svn.dasprids.de
- Milestone 4: [DONE] Proposal confirmation
- Milestone 5: [DONE] Initial documentation exists.
- Milestone 6: [DONE] Everything checked into incubator
7. Class Index
- Zend_Config_Xml
8. Use Cases
The following examples will all result in the same data structure
| UC-01 |
|---|
Classic XML layout
| UC-02 |
|---|
Parent node attributes
| UC-03 |
|---|
Short params (variant 1)
| UC-04 |
|---|
Short params (variant 2)
| UC-05 |
|---|
Short params (variant 3)
9. Class Skeletons
Something I wanted to see some time ago, was the possibility to describe the type of the value, within an attribute.
That could look like this:
<database>
<adapter>pdo_mysql</adapter>
<params>
<host type="string">localhost</host>
<username type="string"></username>
<password type="string"></password>
<dbname type="string"></dbname>
</params>
</database>
<errorReporting type="int">0</errorReporting>
In most cases PHP can cast the right type, but there are cases where this fails.
In principle I like the idea though I worry about having too many ways to do the same thing which may make life harder for maintenance of config files long term.
Regards,
Rob...
Well, the one likes it this way, the other likes it that way. I have also implemented multiple ways since Short params (variant 2) allows having non letter characters as parameter names, like numbers. But I personally would use Short params (variant 3) more often. Short params (variant 1) is for those guys who like the classic way but dislike to always name the parameter name twice (in the opening and the closing tag).
| Zend Comments This proposal has been accepted for Standard Library Incubator inclusion provided the following changes:
|
ZF Home Page
Code Browser
Wiki Dashboard
I would very much like to see this happen in 1.6