mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Added Laravel's env helper
This commit is contained in:
36
module/Common/functions/functions.php
Normal file
36
module/Common/functions/functions.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
if (! function_exists('env')) {
|
||||
/**
|
||||
* Gets the value of an environment variable. Supports boolean, empty and null.
|
||||
* This is basically Laravel's env helper
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
* @link https://github.com/laravel/framework/blob/5.2/src/Illuminate/Foundation/helpers.php#L369
|
||||
*/
|
||||
function env($key, $default = null)
|
||||
{
|
||||
$value = getenv($key);
|
||||
if ($value === false) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
switch (strtolower($value)) {
|
||||
case 'true':
|
||||
case '(true)':
|
||||
return true;
|
||||
case 'false':
|
||||
case '(false)':
|
||||
return false;
|
||||
case 'empty':
|
||||
case '(empty)':
|
||||
return '';
|
||||
case 'null':
|
||||
case '(null)':
|
||||
return null;
|
||||
}
|
||||
|
||||
return trim($value);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,6 @@ class CacheFactory implements FactoryInterface
|
||||
*/
|
||||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
|
||||
{
|
||||
return getenv('APP_ENV') === 'pro' ? new ApcuCache() : new ArrayCache();
|
||||
return env('APP_ENV', 'dev') === 'pro' ? new ApcuCache() : new ArrayCache();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
return [
|
||||
|
||||
'rest' => [
|
||||
'username' => getenv('REST_USER'),
|
||||
'password' => getenv('REST_PASSWORD'),
|
||||
'username' => env('REST_USER'),
|
||||
'password' => env('REST_PASSWORD'),
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user