Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,6 @@ cypress/videos/

# rector
.rector.result.cache

#dotenv
.env
18 changes: 11 additions & 7 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@

Mage::register('original_include_path', get_include_path());

if (!empty($_SERVER['MAGE_IS_DEVELOPER_MODE']) || !empty($_ENV['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
ini_set('display_errors', '1');
ini_set('error_prepend_string', '<pre>');
ini_set('error_append_string', '</pre>');
}

/**
* Set include path
*/
Expand Down Expand Up @@ -59,6 +52,17 @@
include_once $path;
}

$dotenv = Dotenv\Dotenv::createImmutable(BP);
$dotenv->safeLoad();
$dotenv->ifPresent(['MAGE_IS_DEVELOPER_MODE', 'OPENMAGE_CONFIG_OVERRIDE_ALLOWED'])->isInteger();

if (!empty($_SERVER['MAGE_IS_DEVELOPER_MODE']) || !empty($_ENV['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
ini_set('display_errors', '1');
ini_set('error_prepend_string', '<pre>');
ini_set('error_append_string', '</pre>');
}

/**
* Main Mage hub class
*/
Expand Down
7 changes: 5 additions & 2 deletions app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,15 @@ public function setEnvStore(array $envStorage): void

/**
* @return array<string, int|string>
* @SuppressWarnings("PHPMD.Superglobals")
*/
public function getEnv(): array
{
if (empty($this->envStore)) {
$env = getenv();
$env = array_filter($env, function ($key) {
// Use $_ENV instead of getenv() because phpdotenv populates $_ENV with both system environment variables
// and variables from the .env file. This ensures that configuration overrides from .env are respected.
// getenv() would only return system environment variables, not those loaded from .env.
$env = array_filter($_ENV, function ($key) {
return str_starts_with($key, self::ENV_STARTS_WITH);
}, ARRAY_FILTER_USE_KEY);
$this->envStore = $env;
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"symfony/string": "^6.4",
"symfony/translation-contracts": "^3.5",
"symfony/validator": "^6.4",
"tinymce/tinymce": "^8.0"
"tinymce/tinymce": "^8.0",
"vlucas/phpdotenv": "^5.6"
},
"require-dev": {
"ext-xmlreader": "*",
Expand Down
223 changes: 222 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions docs/content/developers/samples/env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
hide:
- toc
---

# `.env`

Load environment variables from a `.env` file in the project root.

### Supported variables:

- `MAGE_IS_DEVELOPER_MODE` (integer: 0 or 1): Enables developer mode if set to 1.
- `OPENMAGE_CONFIG_OVERRIDE_ALLOWED` (integer: 0 or 1): Allows config override if set to 1.
- `OPENMAGE_CONFIG__*` (string): Any variable prefixed with `OPENMAGE_CONFIG__` will be used as a config override.

### Validation:

- `MAGE_IS_DEVELOPER_MODE` and `OPENMAGE_CONFIG_OVERRIDE_ALLOWED` must be integers if present.

### Integration:

- These variables can be set in the `.env` file, or via environment variables (`$_SERVER`/`$_ENV`).
- `.env` values are loaded first, but can be overridden by actual environment variables.

```ini
MAGE_IS_DEVELOPER_MODE=1
OPENMAGE_CONFIG_OVERRIDE_ALLOWED=1
OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME="My OpenMage Store"
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ nav:
- 'Multistore':
- developers/error-pages.md
- 'Samples':
- developers/samples/env.md
- developers/samples/php-ini.md
- developers/samples/robots-txt.md
- 'Guides':
Expand Down
Loading