Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 1, 2023
1 parent 7b7dd6b commit 10f3b13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 42 deletions.
50 changes: 25 additions & 25 deletions src/Illuminate/Support/Env.php
Expand Up @@ -65,6 +65,31 @@ public static function getRepository()
return static::$repository;
}

/**
* Get the value of an environment variable.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function get($key, $default = null)
{
return self::getOption($key)->getOrCall(fn () => value($default));
}

/**
* Get the value of a required environment variable.
*
* @param string $key
* @return mixed
*
* @throws \RuntimeException
*/
public static function getOrFail($key)
{
return self::getOption($key)->getOrThrow(new RuntimeException("Environment variable [$key] has no value."));
}

/**
* Get the possible option for this environment variable.
*
Expand Down Expand Up @@ -97,29 +122,4 @@ protected static function getOption($key)
return $value;
});
}

/**
* Gets the value of a required environment variable.
*
* @param string $key
* @return mixed
*
* @throws \RuntimeException
*/
public static function getRequired($key)
{
return self::getOption($key)->getOrThrow(new RuntimeException("[$key] has no value"));
}

/**
* Gets the value of an environment variable.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public static function get($key, $default = null)
{
return self::getOption($key)->getOrCall(fn () => value($default));
}
}
15 changes: 0 additions & 15 deletions src/Illuminate/Support/helpers.php
Expand Up @@ -139,21 +139,6 @@ function env($key, $default = null)
}
}

if (! function_exists('requireEnv')) {
/**
* Gets the value of a required environment variable.
*
* @param string $key
* @return mixed
*
* @throws \RuntimeException
*/
function requireEnv($key)
{
return Env::getRequired($key);
}
}

if (! function_exists('filled')) {
/**
* Determine if a value is "filled".
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/SupportHelpersTest.php
Expand Up @@ -1017,13 +1017,13 @@ public function testRequiredEnvVariableThrowsAnExceptionWhenNotFound(): void
{
$this->expectExceptionObject(new RuntimeException('[required-does-not-exist] has no value'));

requireEnv('required-does-not-exist');
Env::getOrFail('required-does-not-exist');
}

public function testRequiredEnvReturnsValue(): void
{
$_SERVER['required-exists'] = 'some-value';
$this->assertSame('some-value', requireEnv('required-exists'));
$this->assertSame('some-value', Env::getOrFail('required-exists'));
}

public static function providesPregReplaceArrayData()
Expand Down

0 comments on commit 10f3b13

Please sign in to comment.