Skip to content

Commit 9989fac

Browse files
author
Pascal Querner
committed
feat: add env flag to disable/enable feature
1 parent f24bb9f commit 9989fac

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
1616
{
1717
protected const ENV_STARTS_WITH = 'OPENMAGE_CONFIG';
18+
protected const ENV_FEATURE_ENABLED = 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED';
1819
protected const ENV_KEY_SEPARATOR = '__';
1920
protected const CONFIG_KEY_DEFAULT = 'DEFAULT';
2021
protected const CONFIG_KEY_WEBSITES = 'WEBSITES';
@@ -196,6 +197,10 @@ public function getEnv(): array
196197
}, ARRAY_FILTER_USE_KEY);
197198
$this->envStore = $env;
198199
}
200+
if (!isset($this->envStore[static::ENV_FEATURE_ENABLED])) {
201+
$this->envStore = [];
202+
return $this->envStore;
203+
}
199204
return $this->envStore;
200205
}
201206

tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use OpenMage\Tests\Unit\OpenMageTest;
1919
use Varien_Simplexml_Config;
2020

21+
/**
22+
* @group Mage_Core_EnvLoader
23+
*/
2124
class EnvironmentConfigLoaderTest extends OpenMageTest
2225
{
2326
public const XML_PATH_GENERAL = 'general/store_information/name';
@@ -49,6 +52,30 @@ public function testBuildPath(): void
4952
/**
5053
* @group Helper
5154
*/
55+
public function testEnvFilter(): void
56+
{
57+
$environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();
58+
$environmentConfigLoaderHelper->setEnvStore([
59+
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value"
60+
]);
61+
// empty because env flag is not set
62+
$env = $environmentConfigLoaderHelper->getEnv();
63+
$this->assertIsArray($env);
64+
$this->assertEmpty($env);
65+
$environmentConfigLoaderHelper->setEnvStore([
66+
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value",
67+
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1 // enable feature
68+
]);
69+
// flag is set => feature is enabled
70+
$env = $environmentConfigLoaderHelper->getEnv();
71+
$this->assertIsArray($env);
72+
$this->assertNotEmpty($env);
73+
}
74+
75+
/**
76+
* @group Mage_Core
77+
* @group Mage_Core_Helper
78+
*/
5279
public function testBuildNodePath(): void
5380
{
5481
$environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();

0 commit comments

Comments
 (0)