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

[Messenger] Document the ActivationMiddlewareDecorator #10035

Closed
Milestone
@ogizanagi

Description

@ogizanagi

Relates tosymfony/symfony#27320

This middleware is used to enable/disable a middleware based on an arbitrary condition. Main use-case is for maintaining a unique list of middleware across environments, but disabling/enabling some in test env for instance (but there are many others). It accepts either a simple boolean or a callable returning a boolean.

Usage when using the component standalone should be straightforward enough, but not as obvious when using within the framework.
When used with the framework, it leverages Symfony DI capabilities (usingservice decoration). It can uses a simple parameter value, the result of an expression, or even a callable injected in its constructor (by extending the decorator or by using DI):

TestOnlyMiddleware:~test.TestOnlyMiddleware:class:Symfony\Component\Messenger\Middleware\Enhancers\ActivationMiddlewareDecoratordecorates:TestOnlyMiddlewarearguments:        -"@test.TestOnlyMiddleware.inner"        -"@=parameter('kernel.environment') === 'test'"

using an invokable service:

TestOnlyMiddleware:~ActivationStrategyService: ~# invokable servicetest.TestOnlyMiddleware:class:Symfony\Component\Messenger\Middleware\Enhancers\ActivationMiddlewareDecoratordecorates:TestOnlyMiddlewarearguments:        -"@test.TestOnlyMiddleware.inner"        -"@StrategyService"

using a method of a service as a closure (dynamically executed, as previously):

TestOnlyMiddleware:~ActivationStrategyService:~test.TestOnlyMiddleware:class:Symfony\Component\Messenger\Middleware\Enhancers\ActivationMiddlewareDecoratordecorates:TestOnlyMiddlewarearguments:        -"@test.TestOnlyMiddleware.inner"        -["@StrategyService", 'isEnabled']

Note: a more concise syntax can be used leveraging anonymous services:

TestOnlyMiddleware:class:Symfony\Component\Messenger\Middleware\Enhancers\ActivationMiddlewareDecoratorarguments:        -!service{ class: TestOnlyMiddleware }        -"@=parameter('kernel.environment') === 'test'"

[...]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp