feature #29781 [DI] Add trim env processor (ogizanagi)
This PR was merged into the 4.3-dev branch.
Discussion
----------
[DI] Add trim env processor
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks? | no <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass? | yes <!-- please add some, will be required by reviewers -->
| Fixed tickets | #26708 <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | Todo
Which is especially useful in combination with the `file` env processor.
Commits
-------
e226492db7
[DI] Add trim env processor
This commit is contained in:
commit
0083ba1d88
@ -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
|
||||||
|
@ -44,6 +44,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',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,6 +195,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