本文介绍了PHP - 应用程序配置文件存储为--ini,php,sql,缓存,php类,JSON,php数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想决定如何储存应用程式设定的最佳方式。有这么多选项。

I am trying to decide on the best way to store my applications configuration settings. There are so many options.

我看到的大多数应用程序使用了一个简单的require和一个包含变量的PHP文件。似乎有更先进的技术在那里。

The majority of applications I have seen have used a simple require and a PHP file that contains variables. There seem to be far more advanced techniques out there.

你用过什么?
什么是最高效?
最安全?

What have you used?What is most efficient?What is most secure?

推荐答案

最好的办法是(php变量),并将其包装在一个类。这样,您可以稍后更改实现,而不更改任何客户端代码。创建配置类实现的接口,并使客户端代码使用接口方法。如果以后决定将配置存储在数据库或JSON或其他任何内容中,则可以使用新的实现替换现有实现。确保您的配置类是可测试的,并写入单元测试。

The best thing you can do is the simplest thing that could possibly work (php variables) and wrap it up in a class. That way you can change the implementation later without changing any client code. Create an interface that the configuration class implements and make the client code use the interface methods. If you later decide to store configuration in a database or JSON or whatever, you can simply swap out the existing implementation with a new one. Make sure your configuration class is testable and write unit tests.

这篇关于PHP - 应用程序配置文件存储为--ini,php,sql,缓存,php类,JSON,php数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 01:10