Review main Ready for review

96940[FEATURE] Dispatch Extbase actions through a PSR-15 middleware stack

Alexander Schnitzler CR 0 V +1 Expert +1174 −36 updated 11/11/26, 08:46

Commit message

Extbase offers no way to wrap the dispatching of an action. Events
allow code before and after it, but not around it: there is no
try/finally around the action, no timing across exceptions as needed
for tracing, and no short-circuit with an own response. Today this
needs an own controller base class or an XCLASS.

The Extbase dispatcher now runs every action through the middleware
stack "extbase". Middlewares are registered in
Configuration/RequestMiddlewares.php like for the "frontend" and
"backend" stacks and are ordered and cached by the
MiddlewareStackResolver. The innermost handler resolves the
controller and calls processRequest(). The stack runs once per
action, so a forwarded action passes it again.

Controller forwards use the request processed by the innermost handler
as their basis, so middlewares see their own changes again on the
forward pass and must be idempotent. Forward responses created by
middlewares use the request passed into the stack.

TYPO3 Core registers no middleware in this stack, so the behaviour
without additional middlewares stays the same. The configuration
module lists the new stack.

A follow-up change adds an inner stack around the action invocation,
which takes over validation errors, #[Authorize] and #[RateLimit].

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 5
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/40/96940/5 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/40/96940/5 && git cherry-pick FETCH_HEAD

Review

  • Code review CR 0 Needs a vote
  • Verified V +1 Needs a vote
    • Oliver Klee +1
    • core-ci +1 CI

Relation chain 2

  1. main 96941[!!!][FEATURE] Run Extbase action invocation through a middleware stack Based on this change Work in progress Merge conflict Alexander Schnitzler CR 0 V 0 extbase Expert +1050 −147
  2. 96940 [FEATURE] Dispatch Extbase actions through a PSR-15 middleware stack This change

Merge conflicts 25

Issues 2

Files 23

Show 3 more files

Review log 1823

  1. Alexander Schnitzler uploaded patch set 1 10/20/26, 15:59

  2. core-ci voted on patch set 1 V +1 10/20/26, 16:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/111879

  3. Alexander Schnitzler commented on patch set 1 10/20/26, 17:21

    This change is ready for review.
  4. Simon Schaufelberger commented on patch set 1 10/22/26, 19:22

    ControllerRequestHandler.php:57

    What about using ControllerInterface::class?
  5. Oliver Klee voted on patch set 1 V +1 10/22/26, 19:39

  6. Matthias Vogel uploaded patch set 2 V +1 10/23/26, 09:28

    Preserve middleware request changes in forwards
  7. Matthias Vogel commented on patch set 2 CR +1 V +1 10/23/26, 09:32

    ControllerRequestHandler.php:57 Reply

    Done
  8. Simon Schaufelberger voted on patch set 2 CR +1 V +1 10/23/26, 10:19

  9. Alexander Schnitzler commented on patch set 2 10/23/26, 10:30

    Thanks for taking care.
  10. core-ci voted on patch set 2 V -1 10/23/26, 10:31 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112256

  11. Matthias Vogel rebased onto patch set 3 CR +1 V +1 10/23/26, 10:45

  12. Matthias Vogel voted on patch set 3 CR +1 V +1 10/23/26, 10:46

  13. core-ci voted on patch set 3 V +1 10/23/26, 11:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/112272

  14. Benni Mack commented on patch set 3 10/28/26, 16:01

    does it make sense to deprecate the Event at a later point?
  15. Alexander Schnitzler commented on patch set 3 10/29/26, 10:48

    Reply

    Yes, I think that makes sense, in a separate change once the stack is merged. A middleware in the "extbase" stack can do everything a listener for AfterRequestDispatchedEvent can: it runs once per forward pass, and the pass whose response is not a ForwardResponse is the final one. It even sees the request that was actually processed, while the event only gets the request used to enter the final pass (the RST says so as well). I'd keep 96940 a purely non-breaking feature and follow up with the deprecation of the event in its own change, with its own ticket, RST and scanner entry. Does that work for you?
  16. Benni Mack commented on patch set 3 10/29/26, 11:21

    Reply

    yes
  17. Oli Bartsch commented on patch set 3 10/29/26, 11:39

    Feature-111178-PSR15MiddlewareStackForExtbaseActionDispatching.rst:16 Unresolved

    Can we add a paragraph to the frontend part saying that middlewares run after the allowed controller/action check and the `nonCacheableActions` decision? A middleware that changes controller or action is responsible for both, as with a `ForwardResponse`. Otherwise a middleware can switch a cached USER plugin to a non-cacheable or disallowed action and the output ends up in the page cache.

    Feature-111178-PSR15MiddlewareStackForExtbaseActionDispatching.rst:82 Unresolved

    IMO the `ActionTiming` example should wrap `$handler->handle()` in `try/finally` and record the duration in `finally`. Timing across exceptions is the stated motivation, but as written nothing is recorded when the action fails.

    ControllerRequestHandler.php:43 Unresolved

    The branch that wraps a plain PSR-7 request in `new Request()` is not covered, as the "new request instance" data set in `DispatcherMiddlewareStackTest` passes an Extbase `Request`. Could you add a data set where the middleware passes a plain `ServerRequest` with the `extbase` attribute, asserting dispatch and forward source?

    ForwardResponse.php:43 Unresolved

    I suggest to mark `withSourceRequest()` and `getSourceRequest()` as `@internal`. As public API they give two different forward bases depending on who built the response: the controller's request carries earlier middleware changes into the next pass, so a non-idempotent middleware applies them twice, while a middleware-built response starts from the stack input. So we could keep the attach in `ControllerRequestHandler`, drop the RST section regardign `withSourceRequest()` and document instead that middlewares see their own earlier request changes on a forward pass and must be idempotent.

    Services.yaml:35 Unresolved

    Please consider using `#[AutowireInline(class: MiddlewareDispatcher::class, arguments: [...])]` on the `Dispatcher` constructor, like `frontend/Classes/Http/Application.php:40`. That avoids a named `extbase.middleware-dispatcher` service becoming a de facto contract that others might decorate. Only `extbase.middlewares` needs to stay named, since lowlevel uses it.
  18. Alexander Schnitzler rebased onto patch set 4 CR +1 V +1 11/04/26, 08:55

  19. core-ci voted on patch set 4 V +1 11/04/26, 09:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113262

  20. Alexander Schnitzler uploaded patch set 5 V +1 11/04/26, 10:01

  21. core-ci voted on patch set 5 V +1 11/04/26, 10:11 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/113268

  22. Oliver Klee voted on patch set 5 V +1 11/04/26, 11:51

  23. Alexander Schnitzler commented on patch set 5 11/11/26, 08:46

    Unresolved

    @bo@cedev.de Are you happy with the requested changes?