Skip to content

Commit 1a43758

Browse files
committed
Skip routing get through DefaultEnvironment.
1 parent 41b4fca commit 1a43758

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/DefaultEnvironment.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ class DefaultEnvironment
6161
*/
6262
public static function get(string $name)
6363
{
64-
static $cache = [];
65-
if (!array_key_exists($name, $cache)) {
66-
$cache[$name] = getenv($name);
67-
}
68-
return $cache[$name];
64+
return Environment::get($name);
6965
}
7066

7167
/**

src/Environment.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
/**
66
* Helpers for working with the Drupal environment.
77
*
8-
* @method static mixed get(string $name)
98
* @method static string getEnvironment()
109
* @method static bool isAcquia()
1110
* @method static bool isPantheon()
@@ -41,17 +40,17 @@ class Environment
4140
* @return string
4241
* The class name.
4342
*/
44-
public static function getEnvironmentClass()
43+
public static function getEnvironmentClass(): string
4544
{
4645
static $class;
4746
if (!isset($class)) {
48-
if ($class = getenv('DRUPAL_ENVIRONMENT_CLASS')) {
47+
if ($class = static::get('DRUPAL_ENVIRONMENT_CLASS')) {
4948
// Do nothing. The class was assigned in the if.
5049
} else {
5150
// Intentionally re-assigning the class variable here so that a match
5251
// breaks the foreach loop, or we fall back to the default class.
5352
foreach (static::CLASSES as $class) {
54-
if (getenv($class::ENVIRONMENT_NAME)) {
53+
if (static::get($class::ENVIRONMENT_NAME)) {
5554
break;
5655
}
5756
}
@@ -75,6 +74,24 @@ public static function __callStatic(string $name, array $arguments)
7574
return $class::$name(...$arguments);
7675
}
7776

77+
/**
78+
* Get an environment variable.
79+
*
80+
* @param string $name
81+
* The name of the environment variable to retrieve.
82+
*
83+
* @return mixed
84+
* The environment variable, if it's set.
85+
*/
86+
public static function get(string $name)
87+
{
88+
static $cache = [];
89+
if (!array_key_exists($name, $cache)) {
90+
$cache[$name] = getenv($name);
91+
}
92+
return $cache[$name];
93+
}
94+
7895
/**
7996
* Determine if this is a local environment.
8097
*

0 commit comments

Comments
 (0)