Allow every config options to be set with environment variables
This commit is contained in:
parent
adba68edbc
commit
8521b03cc9
3 changed files with 54 additions and 7 deletions
|
@ -8,6 +8,7 @@ namespace Alltube;
|
|||
|
||||
use Exception;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Jawira\CaseConverter\Convert;
|
||||
|
||||
/**
|
||||
* Manage config parameters.
|
||||
|
@ -222,17 +223,18 @@ class Config
|
|||
|
||||
/**
|
||||
* Override options from environement variables.
|
||||
* Supported environment variables: CONVERT, PYTHON, AUDIO_BITRATE.
|
||||
* Environment variables should use screaming snake case: CONVERT, PYTHON, AUDIO_BITRATE, etc.
|
||||
* If the value is an array, you should use the YAML format: "CONVERT_ADVANCED_FORMATS='[foo, bar]'"
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function getEnv()
|
||||
{
|
||||
foreach (['CONVERT', 'PYTHON', 'AUDIO_BITRATE', 'STREAM'] as $var) {
|
||||
$env = getenv($var);
|
||||
foreach (get_object_vars($this) as $prop => $value) {
|
||||
$convert = new Convert($prop);
|
||||
$env = getenv($convert->toSnake(true));
|
||||
if ($env) {
|
||||
$prop = lcfirst(str_replace('_', '', ucwords(strtolower($var), '_')));
|
||||
$this->$prop = $env;
|
||||
$this->$prop = Yaml::parse($env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,8 @@
|
|||
"zonuexe/http-accept-language": "~0.4.1",
|
||||
"rinvex/countries": "~3.1.0",
|
||||
"php-mock/php-mock-mockery": "~1.3.0",
|
||||
"ext-xsl": "*"
|
||||
"ext-xsl": "*",
|
||||
"jawira/case-converter": "^1.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/var-dumper": "~3.4.1",
|
||||
|
|
46
composer.lock
generated
46
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "07b922cb69b4f4dbd5e537656d559c8d",
|
||||
"content-hash": "c92febd7767c29a4160d24a434ba0d4a",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aura/session",
|
||||
|
@ -374,6 +374,50 @@
|
|||
],
|
||||
"time": "2016-01-20T08:20:44+00:00"
|
||||
},
|
||||
{
|
||||
"name": "jawira/case-converter",
|
||||
"version": "v1.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/jawira/case-converter.git",
|
||||
"reference": "79716629a298e44507a8eed9b997968f39367abc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/jawira/case-converter/zipball/79716629a298e44507a8eed9b997968f39367abc",
|
||||
"reference": "79716629a298e44507a8eed9b997968f39367abc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"suggest": {
|
||||
"pds/skeleton": "PHP Package Development Standards"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Jawira\\CaseConverter\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jawira Portugal"
|
||||
}
|
||||
],
|
||||
"description": "Convert string between **Camel Case** ?, **Snake Case** ?and **Kebab Case** ?.",
|
||||
"keywords": [
|
||||
"camel case",
|
||||
"kebab case",
|
||||
"snake case"
|
||||
],
|
||||
"time": "2019-03-18T05:59:08+00:00"
|
||||
},
|
||||
{
|
||||
"name": "mathmarques/smarty-view",
|
||||
"version": "1.1.2",
|
||||
|
|
Loading…
Reference in a new issue