Review main Abandoned

91599[FEATURE] Add convenience ResponseFactory methods

Benni Mack CR 0 V 0 Hard +564 −60 updated 04/21/26, 14:47

Commit message

PSR-17 interfaces haven't proven to be usable / exchangeable in the
wild for frameworks for the following reasons:

- The interop thought was more important than the convenience for developers
- PHP frameworks kept their existing ways or introduced their own
  convenience wrappers around it.

Even though, we now have a ResponseFactoryInterface implementation
which can be exchanged via DI, we see yet a lot of code using
a simple "new RedirectResponse()" check, which defeats its purpose.

TYPO3 - for this reason - adds this convenience into its own
ResponseFactory, so people can use them right away in their
PHP code - Middlewares, Extbase actions etc.

Just inject TYPO3's ResponseFactory, and use

  return $this->responseFactory->html('NOICE!');

I personally enjoy json(), redirect(), download() and html()
for future features to come!

The benefit:
- Even though the factory is not exchangeable, people can use
  the factory and inject it, so TYPO3 (as a framework) can decide
  the implementation, and userland code can still work with PSR-7
  even though not with PSR-17.
- TYPO3 can eventually replace its own PSR-7 implementation(s)
  with something else, and third-party extension authors do not
  need to change something.
- Last but not least: Less typing for TYPO3 developers.

Review

  • Code review CR 0
  • Verified V 0
    • core-ci +1 CI

Issues 1

Files 11

Review log 1318

  1. Benni Mack uploaded patch set 1 11/12/25, 21:17

  2. Benni Mack marked it work in progress 11/12/25, 21:17

  3. core-ci voted on patch set 1 V -1 11/12/25, 21:26 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/89400

  4. Benni Mack uploaded patch set 2 V -1 01/15/26, 12:03

  5. core-ci voted on patch set 2 V -1 01/15/26, 12:20 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/93509

  6. Benni Mack uploaded patch set 3 V -1 01/15/26, 15:58

  7. Benni Mack marked it ready for review 01/15/26, 16:01

  8. core-ci voted on patch set 3 V +1 01/15/26, 16:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/93529

  9. Simon Schaufelberger commented on patch set 3 02/04/26, 22:33

    Feature-108645-AddConvenienceResponseFactoryMethods.rst:1

    this file needs to be moved to 14.2
  10. Benni Mack commented on patch set 4 V +1 02/05/26, 08:03

    Published edit on patch set 3.
  11. core-ci voted on patch set 4 V -1 02/05/26, 08:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95109

  12. Simon Schaufelberger commented on patch set 4 CR +1 V +1 02/05/26, 10:02

    Feature-108645-AddConvenienceResponseFactoryMethods.rst:1 Reply

    Done
  13. Simon Schaufelberger commented on patch set 4 CR 0 V 0 02/05/26, 10:03

    Unresolved

    Something with the rst file is not correct.
  14. Benni Mack rebased onto patch set 5 V -1 02/07/26, 11:48

  15. core-ci voted on patch set 5 V +1 02/07/26, 11:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95381

  16. Benjamin Franzke commented on patch set 5 02/07/26, 14:57

    Looking at the file/download methods this is more of a response generator/builder than a response factory. How about we name it `ResponseBuilder` (or simply `Responder`), let it use `ResponseFactory` (via ResponseFactoryInterface) internally for all response generations (instead of using all the `FooResponse` classes directly), in order to actually prepare for PSR-7 interchangeability?
  17. Benjamin Franzke commented on patch set 5 02/07/26, 15:06

    Reply Unresolved

    Basically something like: ``` final readonly class Responder { public function __construct( private ResponseFactoryInterface $responseFactory, private StreamFactoryInterface $streamFactory, ) {} public function json( object|array|null $data = [], int $status = 200, ?string $contentType = null, int $encodingOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_UNESCAPED_SLASHES, ): ResponseInterface { $contentType ??= 'application/json; charset=utf-8'; return $this->responseFactory ->createResponse($status) ->withHeader('Content-Type', 'application/json; charset=utf-8') ->withBody($this->streamFactory->createStream((string)json_encode($data))); } public function html( string $content, int $status = 200, ?string $contentType = null ): ResponseInterface { $contentType ??= 'text/html; charset=utf-8'; return $this->responseFactory ->createResponse($status) ->withHeader('Content-Type', $contentType) ->withBody($this->streamFactory->createStream($content)); } ``` This allows to switch the `ResponseFactoryInterface` implemenetation later on.
  18. Benni Mack abandoned the change 04/21/26, 14:47

    won't do this DX change