Last active
September 15, 2017 18:31
-
-
Save texdc/6151978e892a00a0a24ff07d64d88025 to your computer and use it in GitHub Desktop.
A "better" ZF2 application config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
namespace {owner}\{project}\environment; | |
final class ApplicationConfig | |
{ | |
public const ENV_DEVELOPMENT = 'development'; | |
public const ENV_TEST = 'test'; | |
public const ENV_STAGING = 'staging'; | |
public const ENV_PRODUCITON = 'production'; | |
private const CACHE_DIR = 'data/config/'; | |
private $modules : array; | |
private $devModules : array; | |
public function __construct(array $modules = [], array $devModules = []) | |
{ | |
$this->modules = $modules; | |
$this->devModules = $modules + $devModules; | |
} | |
public function build(string $anEnvironment, string $cacheDir = self::CACHE_DIR) : array | |
{ | |
$isProduction = in_array(strtolower($anEnvironment), [static::ENV_PRODUCTION, static::ENV_STAGING]); | |
return [ | |
'modules' => ($isProduction) ? $this->modules : $this->devModules, | |
'module_listener_options' => [ | |
'module_paths' => ['./module', './vendor'], | |
'config_glob_paths' => ['config/autoload/{{,*.}global,{,*.}local}.php'], | |
'config_cache_enabled' => $isProduction, | |
'config_cache_key' => 'app_config', | |
'module_map_cache_enabled' => $isProduction, | |
'module_map_cache_key' => 'module_map', | |
'cache_dir' => $cacheDir, | |
'check_dependencies' => $isProduction, | |
], | |
]; | |
} | |
} | |
// define APP_ENV on your server for each environment | |
return (new ApplicationConfig)->build(getenv('APP_ENV')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment