Skip to content

Commit b686cf5

Browse files
committed
minor #17910 [Config] [Configuration] Add enum case as service parameter example (alexandre-daubois)
This PR was merged into the 6.2 branch. Discussion ---------- [Config] [Configuration] Add enum case as service parameter example Fixes #17407 Commits ------- 701f74b [Configuration] Add enum case as service parameter example
2 parents fd9b155 + 701f74b commit b686cf5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

configuration.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ reusable configuration value. By convention, parameters are defined under the
189189
app.some_constant: !php/const GLOBAL_CONSTANT
190190
app.another_constant: !php/const App\Entity\BlogPost::MAX_ITEMS
191191
192+
# Enum case as parameter values
193+
app.some_enum: !php/enum App\Enum\PostState::Published
194+
192195
# ...
193196
194197
.. code-block:: xml
@@ -226,6 +229,9 @@ reusable configuration value. By convention, parameters are defined under the
226229
<!-- PHP constants as parameter values -->
227230
<parameter key="app.some_constant" type="constant">GLOBAL_CONSTANT</parameter>
228231
<parameter key="app.another_constant" type="constant">App\Entity\BlogPost::MAX_ITEMS</parameter>
232+
233+
<!-- Enum case as parameter values -->
234+
<parameter key="app.some_enum" type="enum">App\Enum\PostState::Published</parameter>
229235
</parameters>
230236
231237
<!-- ... -->
@@ -237,6 +243,7 @@ reusable configuration value. By convention, parameters are defined under the
237243
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
238244
239245
use App\Entity\BlogPost;
246+
use App\Enum\PostState;
240247
241248
return static function (ContainerConfigurator $containerConfigurator) {
242249
$containerConfigurator->parameters()
@@ -256,6 +263,9 @@ reusable configuration value. By convention, parameters are defined under the
256263
// PHP constants as parameter values
257264
->set('app.some_constant', GLOBAL_CONSTANT)
258265
->set('app.another_constant', BlogPost::MAX_ITEMS);
266+
267+
// Enum case as parameter values
268+
->set('app.some_enum', PostState::Published);
259269
};
260270
261271
// ...
@@ -272,6 +282,10 @@ reusable configuration value. By convention, parameters are defined under the
272282
273283
</parameter>
274284
285+
.. versionadded:: 6.2
286+
287+
Passing an enum case as a service parameter was introduced in Symfony 6.2.
288+
275289
Once defined, you can reference this parameter value from any other
276290
configuration file using a special syntax: wrap the parameter name in two ``%``
277291
(e.g. ``%app.admin_email%``):

0 commit comments

Comments
 (0)