Review main Merged

66553[TASK] Extbase controller actions must return ResponseInterface

Alexander Schnitzler CR +2 V +2 Hard +295 −41 updated 11/30/20, 09:58

Commit message

In the past, Extbase controller actions could return either void,
null, a string, or an object that implemented the __toString()
method. All those return types are now deprecated in favor of
an instance of \Psr\Http\Message\ResponseInterface (PSR-7).

Response objects can be created in the controller by using the
response factory which is injected into all action controllers.

Alternatively, custom response objects can be declared and used
as long as they implement the interface and are therefore PSR-7
compatible.

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Torben Hansen +1
    • Daniel Haupt +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Torben Hansen +1
    • Daniel Haupt +1
    • TYPO3com +1 CI

Issues 1

Files 16

Review log 2936

Show 711 earlier messages
  1. Alexander Schnitzler uploaded patch set 1 11/06/20, 13:00

  2. Alexander Schnitzler wrote 11/06/20, 13:02

    Topic set to extbase
  3. TYPO3com voted on patch set 1 V -1 11/06/20, 13:11 Completed build in 10m 56s on Fri, 6 Nov, 01:11 PM Test Summary: 60 of 74036 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7145

  4. Alexander Schnitzler uploaded patch set 2 11/06/20, 13:12

  5. TYPO3com voted on patch set 2 V +1 11/06/20, 13:25 Completed build in 12m 04s on Fri, 6 Nov, 01:25 PM Test Summary: 73551 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7146

  6. Alexander Schnitzler uploaded patch set 3 11/06/20, 14:53

  7. Alexander Schnitzler wrote 11/06/20, 14:54

    Hashtag added: PSR-7
  8. Alexander Schnitzler wrote 11/06/20, 14:54

    Hashtag added: PSR-17
  9. Alexander Schnitzler uploaded patch set 4 11/06/20, 14:59

  10. TYPO3com voted on patch set 3 V +1 11/06/20, 15:07 Completed build in 12m 55s on Fri, 6 Nov, 03:07 PM Test Summary: 73551 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7151

  11. TYPO3com voted on patch set 4 V +1 11/06/20, 15:17 Completed build in 14m 17s on Fri, 6 Nov, 03:17 PM Test Summary: 73551 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7153

  1. Alexander Schnitzler updated the commit message in patch set 5 11/07/20, 10:54

  2. TYPO3com voted on patch set 5 V +1 11/07/20, 11:07 Completed build in 11m 58s on Sat, 7 Nov, 11:06 AM Test Summary: 73551 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7164

  3. Torben Hansen voted on patch set 5 CR +1 11/26/20, 11:32

  4. Georg Ringer commented on patch set 5 11/26/20, 12:53

    ResponseFactory.php:40

    shouldn't that be string as well?
  5. Georg Ringer commented on patch set 5 11/26/20, 14:37

    hey Alex, thx for getting Extbase more into standards. some thoughts about that. I guess people won't like the overhead they will need in 11 do have no deprecations and in 12. now you need always to write `$this->responseFactory->createHtmlResponse($this->view->render());` comparing that to symfony it is vs `new Response($this->view->render())` So some questions: - coudldn't we have the return value nullable and then just do the `$this->responseFactory->createHtmlResponse($this->view->render());` inside extbase? - or what about something like `return $this->html()` which would call that
  6. Daniel Haupt commented on patch set 5 11/26/20, 20:28

    > - coudldn't we have the return value nullable and then just do the `$this->responseFactory->createHtmlResponse($this->view->render());` inside extbase? I would also prefer this approach, not only to minimize migration work, but also to keep things simple as an `HtmlResponse` is the most common use case.

    ResponseFactoryInterface.php:25

    I would have expected this to return an `HtmlResponse` object. Is the thought false?
  7. Alexander Schnitzler commented on patch set 5 11/27/20, 07:32

    > Patch Set 5: > > hey Alex, thx for getting Extbase more into standards. some thoughts about that. > > I guess people won't like the overhead they will need in 11 do have no deprecations and in 12. > now you need always to write `$this->responseFactory->createHtmlResponse($this->view->render());` That's not a nice solution, I agree. I talked to Benni and there are different philosophies about syntactic sugar and how it looks like. laravel has a different approach then symfony, both have pros and cons. > comparing that to symfony it is vs `new Response($this->view->render())` That's the approach I would like the most actually. Given the user just returns a plain response object, the framework assumes it's html and sets the Content-Type for you. IMHO that's the right amount of magic. > So some questions: > - coudldn't we have the return value nullable and then just do the `$this->responseFactory->createHtmlResponse($this->view->render());` inside extbase? That's contradictring the very idea of this patch. The goal is to have all actions reliably return a ResponseInterface because then we can enable dispatching requests to controllers that do not extend the action controller which currently takes care of developers lazyness. Also, $this->view->render() relies on a view object always being present. Something I want to change. views should be optional at some point, so people can write really slim controllers and actions. > - or what about something like `return $this->html()` which would call that I am fine with such an api although to me it feels strange because I don't return html. To me, html is a string, not a response object.

    ResponseFactoryInterface.php:25 Reply

    There is no need for an implementation type hint because the responses don't have a different api. What makes a response an HtmlResponse is actually not the api but only its state.
  8. Alexander Schnitzler commented on patch set 5 11/27/20, 07:36

    ResponseFactory.php:40 Reply Unresolved

    yes indeed.
  9. Alexander Schnitzler commented on patch set 5 11/27/20, 08:03

    One thing I would like to add. This patch gives the impression that the usage of the response factory is necessary or even mandatory. It's not. People can easily just do > return new Response($this->view->render()); already. The factory is handy if your data source is not a string(stream) or if you don't want to set the default Content-Type yourself. I agree that the PSR is a very architectural approach here which is not necessarily the best user api. Also: We don't actually need Response, an HtmlResponse and a JsonResponse class. All those implement the ResponseInterface and don't offer a different api except for their controllers which do the job of said factory methods. Since all those classes are marked internal I would do the following: Deprecate the JsonResponse and HtmlResponse and have the user use helper methods to create a Response object with the right Content-Type. That's really the only difference between all those response objects currently. If we then only have this one Response object, we can offer the PSR-17 factory and those mentioned helper methods in the Extbase controller: > return $this->html(); or > return $this->htmlResponse(); Those methods are just syntactic sugar then, doing the view rendering magic and relying on the factory. We then have a PSR compatible api and syntactic sugar for the users. wdyt?
  10. Torben Hansen commented on patch set 5 11/27/20, 08:49

    > Also: We don't actually need Response, an HtmlResponse and a JsonResponse class. All those implement the ResponseInterface and don't offer a different api except for their controllers which do the job of said factory methods. > > Since all those classes are marked internal I would do the following: Deprecate the JsonResponse and HtmlResponse and have the user use helper methods to create a Response object with the right Content-Type. That's really the only difference between all those response objects currently. Deprecating JsonResponse and HtmlResponse sounds reasonable to me. Although those classes are marked as internal, extension developers actually use those classes in public extensions. A public PSR-17 factory would be a good solution to handle the request object creation at a central place. > If we then only have this one Response object, we can offer the PSR-17 factory and those mentioned helper methods in the Extbase controller: > > > return $this->html(); > > or > > > return $this->htmlResponse(); > > Those methods are just syntactic sugar then, doing the view rendering magic and relying on the factory. > > We then have a PSR compatible api and syntactic sugar for the users. wdyt? Would be fine for me as long as the documentation explains the "magic" behind those methods.
  11. Alexander Schnitzler marked it work in progress 11/27/20, 08:51

  12. Alexander Schnitzler commented on patch set 5 11/27/20, 08:52

    Putting this patch in WIP mode again since we are discussing possible changes.
  13. Torben Hansen wrote 11/27/20, 09:00

    Removed Code-Review+1 by Torben Hansen <derhansen@gmail.com>
  14. Alexander Schnitzler uploaded patch set 6 11/27/20, 14:35

  15. TYPO3com voted on patch set 6 V +1 11/27/20, 14:46 Completed build in 11m 12s on Fri, 27 Nov, 02:46 PM Test Summary: 32394 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7646

  16. Alexander Schnitzler commented on patch set 6 11/27/20, 14:47

    This change is ready for review.
  17. Torben Hansen commented on patch set 6 11/28/20, 06:20

    ResponseFactory.php:24

    Is this still valid?

    ResponseFactory.php:40

    Should be "string $html"
  18. Daniel Haupt commented on patch set 6 11/28/20, 11:57

    ResponseFactoryInterface.php:25 Reply

    Thanks for your explanation.
  19. Alexander Schnitzler uploaded patch set 7 11/28/20, 13:49

  20. Alexander Schnitzler commented on patch set 7 11/28/20, 13:50

    ResponseFactory.php:24 Reply

    Done

    ResponseFactory.php:40 Reply

    Done
  21. TYPO3com voted on patch set 7 V +1 11/28/20, 14:00 Completed build in 10m 39s on Sat, 28 Nov, 02:00 PM Test Summary: 32394 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-7661

  22. Torben Hansen voted on patch set 7 V +1 CR +1 11/29/20, 12:08

  23. Daniel Haupt voted on patch set 7 V +1 CR +1 11/29/20, 13:13

  24. Georg Ringer voted on patch set 7 V +2 CR +2 11/30/20, 08:09

  25. Georg Ringer merged patch set 8 11/30/20, 09:58