如何在 Zend_Config 中存储数值而不丢失其类型?
我决定将一些应用程序设置从数据库移动到文件系统,以便可以通过 Zend_Config 进行访问。 然而我遇到了一件烦人的事情,Zend_Config 将所有值识别为字符串忽略数据类型。
有没有什么神奇的方法来解析配置文件,保留原始类型,如浮点数、整数、字符串,以及 INI、XML、YAML 或 JSON 的最佳存储方式是什么?
I decided to move some application settings from database to file system to be accessible via Zend_Config.
However I run in to one annoying thing, Zend_Config recognise all values as string ignoring data type.
Is there any magic way to parse config file keeping original types like float, integer, string and what would be best storage for it INI, XML, YAML or JSON?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至少不可能使用
Zend_Config_Xml
:不确定其他人的情况。你可以做很多类似的事情
At least not possible with
Zend_Config_Xml
:Not sure about the others. You can very much do something like
Zend 将使用 JSON 和 YAML 自动将整数、浮点数和布尔值转换为各自的类型。 XML 始终是字符串,而 INI 在选择类型时具有 parse_ini_file() 的所有注意事项和功能。
如果您想要显式类型(例如特定对象),则需要将其包含在序列化数据中。
Zend will automagically turn integers, floats, and bools into their respective types with JSON and YAML. XML is always string, and INI has all the caveats and power of parse_ini_file() when it comes to choosing type.
If you want an explicit type, such as a particular object, you need to include that in the serialized data.