将数据库设置从application.ini中取出并放入环境中

时间:2022-09-12 23:24:45

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.

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

Has anyone here on * 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 .

*上有没有人探讨过将数据库设置从application.ini迁移到环境中的可能性?例如,一种基本方法是在Apache2 envvars文件中存储可能的数据库连接设置,或者可能在/ etc / profile或/ etc / environment中存储。

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

我想这样做有几个原因:

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.

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

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.

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

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.

3)应用程序可以部署到数据库设置不同的多个“生产”环境中。因此,application.ini中可能必须有多个部分 - 例如,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.

正如您所看到的,存在一个关于在服务器端保持数据库设置的争论。因此,在全局区域中的应用程序外部可能有数据库设置供所有应用程序访问可能更好?这可能是它自己的源代码控制,也许是开发人员无法访问的。

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

你们怎么想?有人做过类似的事吗?我喜欢全局application.ini的想法(可能叫做database.ini?)

Looking forward to hearing some responses on the subject.

期待听到有关该主题的一些回应。

Regards,

Steve

1 个解决方案

#1


5  

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.

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

In Bootstrap.php I merge them like below:

在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.');
    }
} 

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.

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

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

就像你看到的那样,你可以从你想要的任何地方带走你的非常见配置:)

#1


5  

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.

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

In Bootstrap.php I merge them like below:

在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.');
    }
} 

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.

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

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

就像你看到的那样,你可以从你想要的任何地方带走你的非常见配置:)