Skip to content

Commit b34b1fa

Browse files
author
Pascal Querner
committed
feat: add env flag to disable/enable feature
1 parent 99a4836 commit b34b1fa

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
@@ -22,6 +22,7 @@
2222
class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
2323
{
2424
protected const ENV_STARTS_WITH = 'OPENMAGE_CONFIG';
25+
protected const ENV_FEATURE_ENABLED = 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED';
2526
protected const ENV_KEY_SEPARATOR = '__';
2627
protected const CONFIG_KEY_DEFAULT = 'DEFAULT';
2728
protected const CONFIG_KEY_WEBSITES = 'WEBSITES';
@@ -203,6 +204,10 @@ public function getEnv(): array
203204
}, ARRAY_FILTER_USE_KEY);
204205
$this->envStore = $env;
205206
}
207+
if (!isset($this->envStore[static::ENV_FEATURE_ENABLED])) {
208+
$this->envStore = [];
209+
return $this->envStore;
210+
}
206211
return $this->envStore;
207212
}
208213

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
use PHPUnit\Framework\TestCase;
2525
use Varien_Simplexml_Config;
2626

27+
/**
28+
* @group Mage_Core_EnvLoader
29+
*/
2730
class EnvironmentConfigLoaderTest extends TestCase
2831
{
2932
public const XML_PATH_GENERAL = 'general/store_information/name';
@@ -53,6 +56,30 @@ public function testBuildPath(): void
5356
$this->assertSame(self::XML_PATH_GENERAL, $path);
5457
}
5558

59+
/**
60+
* @group Mage_Core
61+
* @group Mage_Core_Helper
62+
*/
63+
public function testEnvFilter(): void
64+
{
65+
$environmentConfigLoaderHelper = new EnvironmentConfigLoaderTestHelper();
66+
$environmentConfigLoaderHelper->setEnvStore([
67+
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value"
68+
]);
69+
// empty because env flag is not set
70+
$env = $environmentConfigLoaderHelper->getEnv();
71+
$this->assertIsArray($env);
72+
$this->assertEmpty($env);
73+
$environmentConfigLoaderHelper->setEnvStore([
74+
'OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME' => "some_value",
75+
'OPENMAGE_CONFIG_OVERRIDE_ALLOWED' => 1 // enable feature
76+
]);
77+
// flag is set => feature is enabled
78+
$env = $environmentConfigLoaderHelper->getEnv();
79+
$this->assertIsArray($env);
80+
$this->assertNotEmpty($env);
81+
}
82+
5683
/**
5784
* @group Mage_Core
5885
* @group Mage_Core_Helper

0 commit comments

Comments
 (0)