The request handler now only has three primary responsibilities: deserializing an incoming request body into an entity object and determining the appropriate arguments to pass to the EntityResource's controller methods and which method is appropriate for the request.

Theses three responsibilities are unneeded. The deserialization portion can/should happen in a route enhancer, if at all, determining which method to call should be declared on the route itself and the routing system already has an arguments resolved.

Let's get rid of this superfluous class.

To keep things digestible, let's do that in a series of steps:

  1. #2987603: Make resource type an explicit parameter to each EntityResource method
  2. #2987604: Turn EntityResource into a service
  3. #2987606: Remove config mutation tests from EntityResourceTest - removed this because it doesn't necessarily need to block the other issues.
  4. #2987608: Move deserialization from RequestHandler to JsonApiParamEnhancer
  5. #2987609: Rename the entity parameter from the entity type ID to 'entity' for all routes
  6. #2987610: Remove RequestHandler class and service and add EntityResource methods to each route definition
  7. #2991841: Remove unused parameters from EntityResource methods.

Comments

gabesullice created an issue. See original summary.

gabesullice’s picture

Issue summary: View changes

Added issue links to summary

gabesullice’s picture

So far, the combined result of this is:

 jsonapi.services.yml                                 |   8 ++--
 src/Controller/EntityResource.php                    | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
 src/Controller/EntryPoint.php                        |   2 +-
 src/Controller/RequestHandler.php                    | 187 ++++++----------------------------------------------------------------------
 src/LinkManager/LinkManager.php                      |   2 +-
 src/Normalizer/Value/RelationshipNormalizerValue.php |   2 +-
 src/Routing/Routes.php                               |  40 +++++++++++------
 tests/src/Functional/ConfigurableLanguageTest.php    |   2 +-
 tests/src/Functional/ExternalNormalizersTest.php     |   2 +-
 tests/src/Functional/JsonApiFunctionalTest.php       |  10 ++---
 tests/src/Functional/JsonApiRegressionTest.php       |   2 +-
 tests/src/Functional/MessageTest.php                 |   4 +-
 tests/src/Functional/NodeTest.php                    |   4 +-
 tests/src/Functional/ResourceResponseTestTrait.php   |   3 +-
 tests/src/Functional/ResourceTestBase.php            |  18 ++++----
 tests/src/Functional/TermTest.php                    |   4 +-
 tests/src/Functional/UserTest.php                    |   6 +--
 tests/src/Kernel/Controller/EntityResourceTest.php   | 434 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------
 18 files changed, 350 insertions(+), 585 deletions(-)

That does NOT include "Remove RequestHandler class and service and add EntityResource methods to each route definition" which will almost certainly be a large net reduction.

wim leers’s picture

Woaahhhh! Where is this coming from all of a sudden?! I thought we were gonna focus on the bug reports. I guess you got annoyed by it one time too many? :)

(In any case, thanks for splitting up!)

gabesullice’s picture

Woaahhhh! Where is this coming from all of a sudden?! I thought we were gonna focus on the bug reports. I guess you got annoyed by it one time too many? :)

(In any case, thanks for splitting up!)

Precisely. This has been on my bucket list for months. But it was blocked by the render context we had in the RequestHandler, which you moved to an event subscriber, and the complexity (perhaps perceived) of Routes.php, which we already refactored.

TBH, this was actually pretty low-effort because it's really just pure refactoring. I spent a few hours over the weekend doing this.. consider it therapeutic refactoring :P

wim leers’s picture

Ahhh, so now you feel empowered to make the change, like you can finally do it! Makes sense. (I made those changes in #2948666: Remove JSON API's use of $context['cacheable_metadata'] + #2984964: JSON API + hook_node_grants() implementations: accessing /jsonapi/node/article as non-admin user results in a cacheability metadata leak.)

I like the sound of the plan. And I like the sound of therapeutic refactoring :D

Am reviewing all child issues!

e0ipso’s picture

I don't have a preference either way. My only concern is the complexity uptake of scattering a front controller into services that are not explicitly invoked. Imagine someone wanting to understand the flow of an incoming request.

In any case, I don't have a preference either way.

wim leers’s picture

I think the purpose here is to decrease complexity. I think it should be in any case, otherwise this is not worth doing.

Can you confirm that, @gabesullice?

gabesullice’s picture

I think the purpose here is to decrease complexity.

@Wim Leers. That's definitely my intention!


"Complexity" is probably a bit in the eye of the beholder though, so @e0ipso, I see your point of view. You said that this could "[scatter] a front controller into services that are not explicitly invoked".

You're right that deserialization and parameter resolution will happen before to the controller is called and that's a little magical. But I don't know if I would say it's not explicit. It'll all be declared on the route definition.

In some ways, it'll become more explicit. I.e. the method that actually handles each operation wont be called dynamically through call_user_function_array and the class that handles deserialization could be called something very explicit, like IncomingEntityDeserializer.

gabesullice’s picture

Issue summary: View changes

I've removed #2987606: Remove config mutation tests from EntityResourceTest from the list of sub-issues. It doesn't need to block this progress. It was just easier to remove the config tests than it was to fiddle with them to make them work again. I ended up doing that anyway in #2987608-8: Move deserialization from RequestHandler to JsonApiParamEnhancer, that means we can just move on with the rest of this issue and remove those tests independently.

gabesullice’s picture

Issue summary: View changes

Fixing some issue summary formatting.

gabesullice’s picture

Issue summary: View changes

This let's us start to clean up EntityResource.

Adding #2991841: Remove unused parameters from EntityResource methods.

gabesullice’s picture

gabesullice’s picture

Issue summary: View changes

Formatting.

gabesullice’s picture

Assigned: gabesullice » Unassigned
Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.