[DI] Add trim env processor
This commit is contained in:
parent
44aa362419
commit
e226492db7
@ -4,6 +4,7 @@ CHANGELOG
|
|||||||
4.3.0
|
4.3.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
* added `%env(trim:...)%` processor to trim a string value
|
||||||
* added `%env(default:...)%` processor to fallback to a default value
|
* added `%env(default:...)%` processor to fallback to a default value
|
||||||
|
|
||||||
4.2.0
|
4.2.0
|
||||||
|
@ -45,6 +45,7 @@ class EnvVarProcessor implements EnvVarProcessorInterface
|
|||||||
'resolve' => 'string',
|
'resolve' => 'string',
|
||||||
'default' => 'bool|int|float|string|array',
|
'default' => 'bool|int|float|string|array',
|
||||||
'string' => 'string',
|
'string' => 'string',
|
||||||
|
'trim' => 'string',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +196,10 @@ class EnvVarProcessor implements EnvVarProcessorInterface
|
|||||||
return str_getcsv($env);
|
return str_getcsv($env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('trim' === $prefix) {
|
||||||
|
return trim($env);
|
||||||
|
}
|
||||||
|
|
||||||
throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
|
throw new RuntimeException(sprintf('Unsupported env var prefix "%s".', $prefix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ class RegisterEnvVarProcessorsPassTest extends TestCase
|
|||||||
'resolve' => array('string'),
|
'resolve' => array('string'),
|
||||||
'default' => array('bool', 'int', 'float', 'string', 'array'),
|
'default' => array('bool', 'int', 'float', 'string', 'array'),
|
||||||
'string' => array('string'),
|
'string' => array('string'),
|
||||||
|
'trim' => array('string'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame($expected, $container->getParameterBag()->getProvidedTypes());
|
$this->assertSame($expected, $container->getParameterBag()->getProvidedTypes());
|
||||||
|
@ -233,6 +233,19 @@ class EnvVarProcessorTest extends TestCase
|
|||||||
$this->assertSame('hello', $result);
|
$this->assertSame('hello', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetEnvTrim()
|
||||||
|
{
|
||||||
|
$processor = new EnvVarProcessor(new Container());
|
||||||
|
|
||||||
|
$result = $processor->getEnv('trim', 'foo', function ($name) {
|
||||||
|
$this->assertSame('foo', $name);
|
||||||
|
|
||||||
|
return " hello\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assertSame('hello', $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider validJson
|
* @dataProvider validJson
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user