Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Config] [Configuration] Add enum case as service parameter example#17910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletionsconfiguration.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -189,6 +189,9 @@ reusable configuration value. By convention, parameters are defined under the
app.some_constant: !php/const GLOBAL_CONSTANT
app.another_constant: !php/const App\Entity\BlogPost::MAX_ITEMS

# Enum case as parameter values
app.some_enum: !php/enum App\Enum\PostState::Published

# ...

.. code-block:: xml
Expand DownExpand Up@@ -226,6 +229,9 @@ reusable configuration value. By convention, parameters are defined under the
<!-- PHP constants as parameter values -->
<parameter key="app.some_constant" type="constant">GLOBAL_CONSTANT</parameter>
<parameter key="app.another_constant" type="constant">App\Entity\BlogPost::MAX_ITEMS</parameter>

<!-- Enum case as parameter values -->
<parameter key="app.some_enum" type="enum">App\Enum\PostState::Published</parameter>
</parameters>

<!-- ... -->
Expand All@@ -237,6 +243,7 @@ reusable configuration value. By convention, parameters are defined under the
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\Entity\BlogPost;
use App\Enum\PostState;

return static function (ContainerConfigurator $containerConfigurator) {
$containerConfigurator->parameters()
Expand All@@ -256,6 +263,9 @@ reusable configuration value. By convention, parameters are defined under the
// PHP constants as parameter values
->set('app.some_constant', GLOBAL_CONSTANT)
->set('app.another_constant', BlogPost::MAX_ITEMS);

// Enum case as parameter values
->set('app.some_enum', PostState::Published);
};

// ...
Expand All@@ -272,6 +282,10 @@ reusable configuration value. By convention, parameters are defined under the
something@example.com
</parameter>

.. versionadded:: 6.2

Passing an enum case as a service parameter was introduced in Symfony 6.2.

Once defined, you can reference this parameter value from any other
configuration file using a special syntax: wrap the parameter name in two ``%``
(e.g. ``%app.admin_email%``):
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp