mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-30 21:35:18 +03:00
Added Laravel's env helper
This commit is contained in:
parent
d73d3049b7
commit
30988b10d1
7 changed files with 52 additions and 11 deletions
|
@ -41,7 +41,10 @@
|
||||||
"Shlinkio\\Shlink\\Rest\\": "module/Rest/src",
|
"Shlinkio\\Shlink\\Rest\\": "module/Rest/src",
|
||||||
"Shlinkio\\Shlink\\Core\\": "module/Core/src",
|
"Shlinkio\\Shlink\\Core\\": "module/Core/src",
|
||||||
"Shlinkio\\Shlink\\Common\\": "module/Common/src"
|
"Shlinkio\\Shlink\\Common\\": "module/Common/src"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"module/Common/functions/functions.php"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|
|
@ -3,9 +3,9 @@ return [
|
||||||
|
|
||||||
'database' => [
|
'database' => [
|
||||||
'driver' => 'pdo_mysql',
|
'driver' => 'pdo_mysql',
|
||||||
'user' => getenv('DB_USER'),
|
'user' => env('DB_USER'),
|
||||||
'password' => getenv('DB_PASSWORD'),
|
'password' => env('DB_PASSWORD'),
|
||||||
'dbname' => getenv('DB_NAME') ?: 'shlink',
|
'dbname' => env('DB_NAME', 'shlink'),
|
||||||
'charset' => 'utf8',
|
'charset' => 'utf8',
|
||||||
'driverOptions' => [
|
'driverOptions' => [
|
||||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
|
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'translator' => [
|
'translator' => [
|
||||||
'locale' => getenv('DEFAULT_LOCALE') ?: 'en',
|
'locale' => env('DEFAULT_LOCALE', 'en'),
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
<?php
|
<?php
|
||||||
|
use Shlinkio\Shlink\Core\Service\UrlShortener;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
||||||
'url_shortener' => [
|
'url_shortener' => [
|
||||||
'domain' => [
|
'domain' => [
|
||||||
'schema' => getenv('SHORTENED_URL_SCHEMA') ?: 'http',
|
'schema' => env('SHORTENED_URL_SCHEMA', 'http'),
|
||||||
'hostname' => getenv('SHORTENED_URL_HOSTNAME'),
|
'hostname' => env('SHORTENED_URL_HOSTNAME'),
|
||||||
],
|
],
|
||||||
'shortcode_chars' => getenv('SHORTCODE_CHARS'),
|
'shortcode_chars' => env('SHORTCODE_CHARS', UrlShortener::DEFAULT_CHARS),
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
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)
|
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 [
|
return [
|
||||||
|
|
||||||
'rest' => [
|
'rest' => [
|
||||||
'username' => getenv('REST_USER'),
|
'username' => env('REST_USER'),
|
||||||
'password' => getenv('REST_PASSWORD'),
|
'password' => env('REST_PASSWORD'),
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
Loading…
Add table
Reference in a new issue