Issues

ZF-6720: Zend_Config_Writer has no option to get a string of the config data, it can only output to file

Issue Type:

Improvement

Created:

2009-05-19T02:16:39.000+0000

Last Updated:

2012-11-20T21:38:04.000+0000

Status:

Reopened

Fix version(s):

Reporter:

Maurice Fonk (naneau)

Assignee:

None

Tags:

Zend_Config_Writer

Related issues:

Attachments:

Description

Zend_Config_Writer has no option to obtain a string of the configuration data it will write to a file. There are instances where you would like to work with the string instead of simply writing it to a file. You might want to store the config data in something other than a file, or expose them through a web service.

Comments

Posted by Ben Scholzen (dasprid) on 2009-05-19T02:22:54.000+0000

Why would you want to store a configuration as XML (which kinda is a database) in another database?

Posted by Maurice Fonk (naneau) on 2009-05-19T02:37:11.000+0000

There are many valid reasons (think user-specific configs, that are not predefined), xml is a handier format for storing trees than relational databases anyway. Databases aren't the only application here. I have a service layer which needs access to configuration that is the result of merged configs for which I need an xml string.

Posted by Ben Scholzen (dasprid) on 2009-05-19T03:56:55.000+0000

It's not the sense of a writer to output strings. If you want to store a config object in a database, simply do serialize($config) or something similar.

Posted by Maurice Fonk (naneau) on 2009-05-21T04:00:40.000+0000

Closing the issue with this reply is absolutely not satisfactory and downright insulting, please be professional.

There are many valid reasons one could have to obtain just string and do the actual writing to a i/o stream separately. Creating a web-service which exposes (parts of) a configuration was the one I ran into. I can also see a use case, for xml configs, where one would do XSLT upon the string. Your idea that xml is "kinda a database" is a fallacy as a file-system is one too.

The need to store configurations (that are variable) in a standardized format in a database is the most obvious use case. Your proposed solution to use a serialized config object is extremely poor design and would pin all future queries against that database to a php implementation. While it is true that one could model an actual variable configuration layer in a relational database, ZF offers no support for db based configs.

The fact that the writer already has all the necessary functionality to produce strings makes a fix for this issue easy. Furthermore it could be implemented without breaking the API, although I must say that the file-centric implementation is poorly thought out anyway. What is the rationale behind the limitation towards file-based config writing?

Posted by Ben Scholzen (dasprid) on 2009-05-21T04:17:53.000+0000

Speaking of poor design, it is pretty wrong as well to store XML in a database when you could do it in the correct way. I have created a Zend_Config_Db proposal some time ago, but since there was never much feedback, I had froozen it. If you are actually interested in storing configurations in a database, you should comment on that proposal.

It is not the purpose that has driven the design of the config writers, and if it were, then this issue should be for Zend_Config_Writer and not Zend_Config_Writer_Xml.

It does sound as though the means to your end would be better suited with something like SimpleXML, or one of the other many native PHP XML libraries.

Posted by Maurice Fonk (naneau) on 2009-05-21T05:01:54.000+0000

Agreed, Zend_Config_Db is the ultimate solution for db-based configs. However, that is a completely separate issue from the one at hand here. Ryan makes a fair point that this issue is more related to Zend_Config_Writer in general than Zend_Config_Writer_Xml. Xml output is probably the more requested, but that does not mean that I might not want to expose my configurations in ini format for instance.

Also, for ben, I would suggest you read http://dev.mysql.com/tech-resources/articles/… for some background info about how xml is used in conjunction with relational databases (a quick google should turn up more about this subject).

Posted by Maurice Fonk (naneau) on 2009-05-21T05:04:42.000+0000

Updated the description a little to reflect the fact that this applies to Zend_Config_Writer in general, not just Zend_Config_Writer_Xml

Posted by Bert Van Hauwaert (becoded) on 2009-05-28T01:35:55.000+0000

I need something similar.
I made some modules that you can install. It will execute some SQL-statements, copy some files and it also needs to merge some config-files. I can't and I also don't want to write the merged config to the filesystem. I want to output the config and after a manual check, I will copy and paste the new config in the right file (sometimes, i don't want the changes to be made). Almost everything is already written to make this happen. Just add a toString method or something and copy almost everything from the write method in the new method. The write method will then call the toString method and write everything to the file.

Posted by jw (ronny stalker) on 2010-02-04T22:04:05.000+0000

Here is a hacked extension that allows you to return an XML string.

If the ''file aspects'' were separated/refactored from the ''xml generation'' aspects in the write() method of the parent class, then the extension would be a lot less smelly.

Apologies for breaking code-style convention - i think my way is nicer and easier read...funny that.