使数据库设置脱离application.ini并进入环境 [英] Taking Database Settings out of the application.ini and into the environment

查看:155
本文介绍了使数据库设置脱离application.ini并进入环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在基于Zend的应用程序的传统编码中,数据库设置存储在application.ini中。

In traditional coding of Zend based applications, the database settings are stored in the application.ini . This stores the settings on a per application basis.

StackOverflow上的任何人都在探索将数据库设置从application.ini移动到环境中的可能性吗?例如,一个基本的方法是将可能的数据库连接设置存储在Apache2 envvars文件中,或者可能存储在/ etc / profile或/ etc / environment中。

Has anyone here on StackOverflow explored the possibility of moving database settings from the application.ini into the environment? For example, a basic way would be storing possibly database connections settings in the Apache2 envvars file or possibly in something like /etc/profile or /etc/environment .

我想要这样做的几个原因:

There are a couple of reasons why I would like to do this:

1)在应用程序中具有实时的生产数据库设置存在安全风险。开发人员可能无意中连接到实时数据库,并对客户敏感数据造成损害。这将保护开发人员,业务是最终用户。

1) There is security risk where having live, production database settings within the application. Developers could inadvertedly connect to the live database and cause damage to customer sensitive data. This would protect both developers, the business an end users.

2)难以维护和管理多个应用程序的数据库设置。例如,如果数据库的用户名或密码发生变化,那么我们需要更改application.ini或多个应用程序,这意味着只会再次显示该文件或整个应用程序。

2) It is difficult to maintain and manage the db settings of multiple applications. For example, if a username or password changes for a database, then we would need to change the application.ini or multiple applications that would mean a rollout of just that file or the whole application again.

3)应用程序可以部署到多个数据库设置不同的生产环境。因此,在application.ini中可能会有多个部分,例如production-datacentreX,production-datacentreY。

3) An application may be deployed to mulitple 'production' environments where the database settings differ. Therefore there may have to be multiple sections within the application.ini - for example and production-datacentreX, production-datacentreY.

正如你所看到的,在服务器端保留数据库设置。因此,可能最好在全局区域中的应用程序外部为所有应用程序访问数据库设置?这将是在它自己的源代码控制,也许这是开发人员无法访问。

As you can see, there is an argument on keeping database settings on the server side. Therefore, it may be better to have possibly the database settings outside an application in a global area for all applications to access? This would be in it's own source control perhaps that would be unaccessible to developers.

你们认为什么?任何人做类似的事情?我喜欢全局application.ini(可能称为database.ini?)的想法。

What do you folks think? Anyone done something similar? I like the idea of a global application.ini (possibly called database.ini?)

期待听到一些关于这个问题的回答。

Looking forward to hearing some responses on the subject.

回答,

Steve

推荐答案

在我最后的项目中,我做了类似的事情。我有 application.ini ,它存储在存储库中,包含应用程序的常见设置(查看设置,帮助程序路径,启用布局等)。但是,每个应用程序实例(每个开发人员都有其中一个+测试和开发服务器)有自己的 local.ini 文件(未进行版本控制)与数据库设置和开发指令(启用FirePHP,ZFDebug)。由于这个解决方案,我们可以全局 - application.ini和每个开发人员可以更改设置本地 - 使用 local.ini 文件进行更改。

In my last project I've done something similar. I have application.ini which is stored in repository and contains common settings for application (view settings, helpers path, enable layout and things like that). But, each instance of application (each developer has one of them + testing and development server) has its own local.ini file (which is not versioned) with database settings and development directives (enabling FirePHP, ZFDebug). Thanks to that solution, we can make changes "globally" - application.ini and each developers can change settings "locally" - using local.ini file.

Bootstrap.php 我如下合并:

protected function _initLocalConfig()
{
    $globalConfig = new Zend_Config($this->getOptions(), true);
    try {
        $localConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/local.ini');
        $globalConfig->merge($localConfig);
        $this->setOptions($globalConfig->toArray());
    } catch (Zend_Config_Exception $e) {
        throw new Exception('File /configs/local.ini not found. Create it, it can be empty.');
    }
} 

我在这里使用第二个静态命名的.ini文件,在另一个项目中,我们使用基于主机名的.ini文件。它们也可以是JSON,XML或YAML文件(以利用内置的Zend_Config解析器)或者您可以编写自己的适配器。

I'm using second static named .ini file here, in another project we use .ini files based on host names. They can be also JSON, XML or YAML files (to take advantage of built-in Zend_Config parsers) or you can write your own adapter.

像你看到的,你可以把你的非常见的配置实际上从任何你想要的:)

Like you see, you can take your non-common config practically from anywhere you want :)

这篇关于使数据库设置脱离application.ini并进入环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆