diff --git a/config/config-dev.php b/config/config-dev.php index 1c5f176..1bc8d41 100644 --- a/config/config-dev.php +++ b/config/config-dev.php @@ -139,8 +139,8 @@ $body = $template->render($mapVariables); $prefix = ""; - if (Psr11::environment()->getCurrentConfig() != "prod") { - $prefix = "[" . Psr11::environment()->getCurrentConfig() . "] "; + if (Psr11::environment()->getCurrentEnvironment() != "prod") { + $prefix = "[" . Psr11::environment()->getCurrentEnvironment() . "] "; } return new Envelope(Psr11::container()->get('EMAIL_TRANSACTIONAL_FROM'), $to, $prefix . $subject, $body, true); }, diff --git a/src/Psr11.php b/src/Psr11.php index 1d9bcad..1012535 100644 --- a/src/Psr11.php +++ b/src/Psr11.php @@ -3,9 +3,9 @@ namespace RestReferenceArchitecture; use ByJG\Cache\Psr16\FileSystemCacheEngine; -use ByJG\Cache\Psr16\NoCacheEngine; use ByJG\Config\Container; use ByJG\Config\Definition; +use ByJG\Config\Environment; use ByJG\Config\Exception\ConfigException; use ByJG\Config\Exception\ConfigNotFoundException; use ByJG\Config\Exception\InvalidDateException; @@ -40,14 +40,17 @@ public static function container($env = null): ?Container */ public static function environment(): ?Definition { + $dev = new Environment('dev'); + $test = new Environment('test', [$dev]); + $staging = new Environment('staging', [$dev], new FileSystemCacheEngine()); + $prod = new Environment('prod', [$staging, $dev], new FileSystemCacheEngine()); + if (is_null(self::$definition)) { self::$definition = (new Definition()) - ->addConfig('dev') - ->addConfig('test' , inheritFrom: ['dev']) - ->addConfig('staging', inheritFrom: ['dev']) - ->addConfig('prod', inheritFrom: ['staging', 'dev']) - ->setCache(['dev', 'test'], new NoCacheEngine()) - ->setCache(['prod', 'staging'], new FileSystemCacheEngine()) + ->addEnvironment($dev) + ->addEnvironment($test) + ->addEnvironment($staging) + ->addEnvironment($prod) ; } diff --git a/tests/Functional/Rest/BaseApiTestCase.php b/tests/Functional/Rest/BaseApiTestCase.php index 4719a15..f438c11 100644 --- a/tests/Functional/Rest/BaseApiTestCase.php +++ b/tests/Functional/Rest/BaseApiTestCase.php @@ -40,7 +40,7 @@ public function getPsr7Request(): Request public function resetDb() { if (!self::$databaseReset) { - if (Psr11::environment()->getCurrentConfig() != "test") { + if (Psr11::environment()->getCurrentEnvironment() != "test") { throw new Exception("This test can only be executed in test environment"); } Migration::registerDatabase(MySqlDatabase::class);