Skip to content

Instantly share code, notes, and snippets.

@Thinkscape
Last active December 20, 2015 20:58
Show Gist options
  • Save Thinkscape/6193625 to your computer and use it in GitHub Desktop.
Save Thinkscape/6193625 to your computer and use it in GitHub Desktop.
Example of production/devel runtime config branching with ZF2 skeleton app.
<?php
// Determine ENV
define('APPLICATION_ENV', getenv('APPLICATION_ENV') == 'development' || PHP_SAPI == 'cli' ? 'development' : 'production');
// Load the appropriate config file
return
APPLICATION_ENV == 'development' ?
require __DIR__.'/application.development.config.php' :
require __DIR__.'/application.production.config.php'
;
<?php
// config merging this way is more expensive, but we only do this for DEVELOPMENT
return
\Zend\Stdlib\ArrayUtils::merge(
\Zend\Stdlib\ArrayUtils::merge(include __DIR__.'/application.production.config.php',array(
// --- FIRST PASS ------
'modules' => array(
'ZFTool', // we don't need those two modules in production (only in development)
'ZendDeveloperTools' // and composer won't even bother installing them because of require-dev
),
'module_listener_options' => array(
'module_paths' => false, // <- clear this out
'config_cache_enabled' => false,
'module_map_cache_enabled' => false,
'check_dependencies' => true,
),
)), array(
// --- SECOND PASS ------
'module_listener_options' => array(
'module_paths' => array( // <- use this array instead
'./vendor_dev',
'./vendor',
'./module',
),
)
));
<?php
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'ZfcBase',
'ZfcUser',
'ZfcUserDoctrineORM',
'BjyAuthorize',
'Application',
'ReverseOAuth2',
),
// These are various options for the listeners attached to the ModuleManager
'module_listener_options' => array(
// This should be an array of paths in which modules reside.
// If a string key is provided, the listener will consider that a module
// namespace, the value of that key the specific path to that module's
// Module class.
'module_paths' => array(
'./module',
'./vendor',
),
// An array of paths from which to glob configuration files after
// modules are loaded. These effectively overide configuration
// provided by modules themselves. Paths may use GLOB_BRACE notation.
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
// Whether or not to enable a configuration cache.
// If enabled, the merged configuration will be cached and used in
// subsequent requests.
'config_cache_enabled' => true,
// The key used to create the configuration cache file name.
'config_cache_key' => 'config',
// Whether or not to enable a module class map cache.
// If enabled, creates a module class map cache which will be used
// by in future requests, to reduce the autoloading process.
'module_map_cache_enabled' => true,
// The key used to create the class map cache file name.
'module_map_cache_key' => 'modulemap',
// The path in which to cache merged configuration.
'cache_dir' => 'data/cache',
// Whether or not to enable modules dependency checking.
// Enabled by default, prevents usage of modules that depend on other modules
// that weren't loaded.
'check_dependencies' => false,
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment