envload.php 764 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. declare(strict_types=1);
  3. // make replace _ENV with env
  4. function searchEnvName($name)
  5. {
  6. global $_ENV;
  7. foreach ($_ENV as $configKey => $configValue) {
  8. if (strtoupper($configKey) === $name) {
  9. return $configKey;
  10. }
  11. }
  12. return null;
  13. }
  14. if (getenv('UIM_ENV_REPLACE_ENABLE')) {
  15. foreach (getenv() as $envKey => $envValue) {
  16. global $_ENV;
  17. $envUpKey = strtoupper($envKey);
  18. // Key starts with UIM_
  19. if (strpos($envUpKey, 'UIM_') === 0) {
  20. // Valid env key, set to _ENV
  21. $configKey = substr($envUpKey, 4);
  22. $realKey = searchEnvName($configKey);
  23. if ($realKey !== null) {
  24. $_ENV[$realKey] = $envValue;
  25. }
  26. }
  27. }
  28. }