New in Symfony 7.2: Non-Empty Container Parameters
October 31, 2024 • Published by Javier Eguiluz
Symfony 7.2 is backed by:
Symfony provides utilities to validate and process configuration parameters before injecting them as parameters in the application. This is common, for example, when defining semantic configuration in bundles.
Sometimes, bundles and other packages rely on configuration parameters that might or might not be defined in the application. Instead of re-validating those parameters repeatedly across all packages, Symfony 7.2 makes this easier.
Use the new parameterCannotBeEmpty()
method on the container to enforce that
a parameter must exist and have a non-empty value:
1 2 3 4
$container->parameterCannotBeEmpty(
'app.private_key',
'Did you forget to configure a value for the "app.private_key" parameter?'
);
Symfony will check that the app.private_key
parameter exists and that its value
is not null
, an empty string, or an empty array. If any of these conditions
fail, you'll see the following error message:
1 2
You have requested a non-existent parameter "app.private_key".
Did you forget to configure a value for the "app.private_key" parameter?
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.