Does the Zend Framework separate developer environment information from configuration?

I am just starting with the big Zend Framework project. Something bothers me: most of the configuration seems to be stored in a single file in application/configs/application.ini . This file includes various things important for the application function, such as the application namespace, controller plugins, etc., as well as data for entering the database. I have external contractors who need to work on this project, but I do not want them to have all the data in my database. In Zend, how do you separate information about the environment, such as db logins (which may differ for different developers) from the application configuration (which will be the same for everyone)?

+6
source share
4 answers

I agree that this is harder in ZF than it should be, I hope this is an area that will be improved in future versions.

At the same time, it’s quite easy to merge two configuration files with Zend_Config, and this is something you can take advantage of. If you open public/index.php , you will see a section below where it creates an instance of Zend_Application. By default, the second parameter is the full path to your configuration file, but instead you can pass an existing Zend_Config object. Thus, you create two configuration objects: application.ini and environment.ini (call it what you want), merge them together and then pass them to Zend_Application:

 $config = new Zend_Config_Ini( APPLICATION_PATH.'/configs/application.ini', APPLICATION_ENV, array('allowModifications' => true) ); $environment = new Zend_Config_Ini( APPLICATION_PATH.'/configs/environment.ini', APPLICATION_ENV ); $config->merge($environment); $application = new Zend_Application(APPLICATION_ENV, $config); $application->bootstrap() ->run(); 

With this approach, you save all the standard materials in application.ini and move the database material to environment.ini. Then you save application.ini in the source control, add environment.ini to gitignore / svn: ignore it and create a dummy environment.ini.dist file that your other developers can use to configure their local projects.

Note. If you commented on the require_once calls in the ZF library files for performance reasons, you may need to run some of the Zend_Config classes in public / index.php to make this work. This should be obvious from the mistakes.

+8
source

What I do for Symfony and Zend is not checking configuration files with similar information.

Instead, I create a config.dist file that I store in SVN / Git, which has all the necessary information to run the application, and then the dummy information for the confidential credentials and what not. Then on each machine (local dev, production, staging) I copy this file to the real cnfig file name and edit it with the corresponding specific environment details.

+5
source

I use PHP based configuration files this way (application.php):

 <?php return array_merge_recursive(array( 'bootstrap' => array( 'phpSettings' => array( 'display_startup_errors' => 0, 'display_errors' => 0 ), 'path' => APPLICATION_PATH . '/Bootstrap.php', 'class' => 'Bootstrap', ) /** all other general config stuff as well **/ ), include APPLICATION_PATH . '/configs/' . APPLICATION_ENV . '.php'); 

And one related to the environment (e.g. development.php):

 <?php return array( 'phpSettings' => array( 'display_startup_errors' => 1, 'display_errors' => 1, 'error_reporting' => E_ALL, ), 'resources' => array( /** log to browser only for development environment **/ 'log' => array( 'Firebug' => array( 'writerName' => 'Firebug', 'filterName' => 'Priority', 'filterParams' => array( 'priority' => Zend_Log::DEBUG ) ) ), 'db' => array( /** Development Database settings, only need to overwrite the new ones **/ ) ) ); 

An idea stolen from this page (you would, of course, ignore development.php).

+1
source

You can create two ini files in application/configs . The first file, application.ini contains most of your configuration configuration. The second secrets.ini file contains your database passwords and other things that you do not want to check in the original control. Now you can check your application.ini file in the source control. Do not check secrets.ini - ask your VCS to ignore it - and force each developer to create this file from scratch in their personal checks.

You can then write a method in your application/Bootstrap.php class to read both files, merge them together into a Zend_Config object, and write this object to Zend_Registry .

I don't think this solution is perfect, but in the past it worked for me.

0
source

Source: https://habr.com/ru/post/893728/


All Articles