Overview
This page contains information not otherwise found in the issue tracker, especially for proposed improvements and notes on design decisions.
Allow loading of multiple sections
Adapters could allow the section specification parameter to be mixed:
- string - Names a single section to be loaded (currently supported)
- array - Array of strings, which are the names of multiple sections to be loaded
- null - Indicates that all sections should be loaded
Implementing this would mean:
- Adding a getSectionName() method would no longer be semantically appropriate
- First level properties would correspond with section names (e.g., $config->sectionName)
See ZF-413
Add getSectionName() method
This is in order to easily retrieve the configuration data section name upon demand without having to store it outside the class or create an extending class. This is particularly useful where a Zend_Config object instance is stored and fetched using an application registry.
Add getWithDefault() method
Ability to simplify:
Not sure how function signature would look though.
See ZF-414
Test for circular section extension in adapters
A configuration data section may inherit from another section, but an exception should be thrown where circular inheritance is detected by the storage adapter.
See ZF-415
Remove Zend_Config_Array
The current version of Zend_Config may be instantiated with an array of configuration data. Zend_Config_Array is no longer necessary, since its only added value is that it loads a specified file, and it rather arbitarily requires that the array be named $config.
See ZF-416
Re loading of multiple sections:
I think that getSectionName() would still be useful as it would still contain what was loaded. Instead of just returning a string, it would return a string, an array of string or null. (i.e. the same as what was used to load the config originally.)
Is the plan for there to be an ->update() function that writes to the ini or xml config file? What is the $allowModifications actually for?
This would be useful for installing a cms (like the one I'm writing at the moment). At the end of the install process you will have tested the db connections etc provided by the user and could now safely write the config file... but alas, zend config doesn't do it. Yet?
Also, in my cms I have a flag in the config file called site.downForMaintenance which lets me gracefully tell the user that the site is down before trying to connect to non existant db's etc.
It would be nice to be able to trigger that from the backend without having to write a fwrite function to go and do it for me.
Thanks! ZF rocks the party!
Not sure how I get to the uber leet status of someone who can report bugs, but I just noticed that in 0.60 (dont know if this is a new thing, assume not) that an exclamation mark in the config file comments cause it to throw a warning.
For example
- This is a test comment!
or
// This is a test comment!
Both throw a warning:
Warning: Error parsing ./application/config.ini on line 23 in /var/www/clarity/library/Zend/Config/Ini.php on line 73
Thanks again!
j.
That'll teach me to preview...
The:
- This is a test comment!
was meant to be:
# This is a test comment!
Wiki Markup actually means something...
J.
Hi Jonathan,
Thanks for the report!
Can you provide a minimal complete config file that does this?
From the PHP manual for parse_ini_file, comments start with a ; (semi colon) rather than a // so I suspect that the problem you are seeing is due to that.
Regards,
Rob...
Hi Rob
Yup, you're right... it parses fine with the ; as the commenter.
I also realise that the strange behaviour I'm seeing with the # and // commenting is probably just parse_ini_file() ignoring lines that it can't make sense of... Although one would expect a parse error since when I print_r($config) I don't see any remnants of my commenting in the config array.
Technically I guess this could be considered a parse_ini_file() bug as you would expect it to throw an error/warning when it tries to parse a config file like this:
As you can imagine this behaviour can be confusing to a developer who thinks that their #'s are commenting.
Also Rob, do you have an answer for my first question re writing back to config files?
Thanks again,
j.
Hi All..
Funny Rob should mention Zend_Config_Writer ive been needing to write back Xml files and have knocked up a very simple Config_Xml_Writer class to extend the Config_Xml class
So far it has proved very useful in writing Config data back to an XML file..
I thought that other may also benefit from it if they are stuck for writing one themselves. its not 100% but its simple enough to read and tweak.
The source is posted at www.zucchi.me.uk/2008/06/zend_config_xml_writer-almost/
Matt
ZF Home Page
Code Browser
Wiki Dashboard
getWithDefault() could be: get($name, $default = null)