Review main Merged

69676[TASK] Avoid ObjectManager in ext:extbase

Christian Kuhn CR +2 V +2 Hard +298 −338 updated 07/22/21, 14:54

Commit message

This finishes removal of regular extbase ObjectManager
usages throughout the core: All left over places are
fallback situations if extensions don't provide proper
service definitions.

Most places are casual replacements, many of them have
been prepared with previous patches. Some places like
Query and QueryResult still need special handling: The
patch introduces some 'ForwardCompatible' interfaces
implemented by core to otherwise OM-fallback if extensions
didn't catch up yet. This avoids expensive runtime
reflection in potentially often-called areas.

When this patch is merged, a final patch can be done,
including a ReST with some dedicated transition tips
and the ultimate ObjectManager deprecation.

Review

  • Code review CR +2 Done
    • Christian Kuhn +2
    • Jochen Roth +1
    • Benni Mack +1
  • Verified V +2 Done
    • Christian Kuhn +2
    • Jochen Roth +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 3

Files 25

Show 5 more files

Review log 1929

Show 24 earlier messages
  1. Christian Kuhn uploaded patch set 1 06/30/21, 18:28

  2. Christian Kuhn uploaded patch set 2 06/30/21, 18:29

  3. core-ci voted on patch set 1 V -1 06/30/21, 18:30 Core CI is not happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12868

  4. core-ci voted on patch set 2 V -1 06/30/21, 18:31 Core CI is not happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12869

  1. Christian Kuhn uploaded patch set 3 06/30/21, 19:11

  2. core-ci voted on patch set 3 V -1 06/30/21, 19:23 Core CI is not happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12870

  3. Christian Kuhn uploaded patch set 4 06/30/21, 20:45

  4. core-ci voted on patch set 4 V -1 06/30/21, 20:56 Core CI is not happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12875

  5. Christian Kuhn uploaded patch set 5 06/30/21, 21:59

  6. core-ci voted on patch set 5 V +1 06/30/21, 22:10 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12877

  7. Christian Kuhn updated the commit message in patch set 6 06/30/21, 22:41

  8. Christian Kuhn updated the commit message in patch set 7 06/30/21, 22:43

  9. core-ci voted on patch set 6 V +1 06/30/21, 22:54 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12878

  10. core-ci voted on patch set 7 V +1 06/30/21, 22:56 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12879

  11. Christian Kuhn rebased onto patch set 8 06/30/21, 23:13

  12. core-ci voted on patch set 8 V +1 06/30/21, 23:22 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12880

  13. Benjamin Franzke commented on patch set 8 CR -1 07/09/21, 11:09

    ActionController.php:403

    This seems to be breaking, existing validators may not be public symfony services. I think we need the occasonal `container->has ? container->get : objectManager->get` dance here.

    GenericViewResolver.php:38

    Why not inject right now? Does that result in technical problems?

    Query.php:124

    Again here, I'd like to inject right now as well.

    Query.php:240

    return here looks wrong, did you mean to return after the if-condition?

    Query.php:243

    Hm, when is this codepath triggered? QueryResultInterface will always be available in the container, no? Only case I can think of is installtool context where I guess this is never used.. I think we could remove the $this->container->has(QueryResultInterface::class) chekc above.

    QueryFactory.php:44

    Sorry, to repeat myself, but would already try to inject right now.

    QueryFactory.php:55

    Should always be true, drop else block?

    PropertyMapper.php:82

    This seems to be breaking, existing type converters may not be public symfony services. I think we need the occasonal `container->has ? container->get : objectManager->get` dance here.

    ObjectConverter.php:68

    Why nullable? Should always be injected…

    ObjectConverter.php:256

    Hm, so we only have a plan for objects without constructor arguments. These objects are not services, but rather data objects, so it's not really straight forward for our users to enable those data object as public services, especially if they are (proper) plain object. I think we should rather expect object that ObjectConverter targets to *avoid* injection and rather to be plain objects. What I'm saying: Should we maybe ask objectmananger in v11 whether the object asks for dependency injection and then provide it (plus deprecation logging), and otherwise use GeneralUtility::makeInstance.
  14. Benjamin Franzke uploaded patch set 9 07/09/21, 11:21

  15. Benjamin Franzke commented on patch set 9 07/09/21, 11:21

    GenericViewResolver.php:38 Reply

    Done

    Query.php:124 Reply

    Done

    Query.php:240 Reply

    Nevermind, I see why you did it, alright. of course we can only use the object if we're able to set the query.

    QueryFactory.php:44 Reply

    Done

    ObjectConverter.php:68 Reply

    Done
  16. Benjamin Franzke commented on patch set 9 07/09/21, 11:25

    Agree with the patch in general,

    Query.php:243 Reply

    Nevermind, I see, when QueryResultInterface is aliased to a custom service that doesn't implement ForwardCompatibleQueryResultInterface.
  17. core-ci voted on patch set 9 V -1 07/09/21, 11:31 Core CI is not happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/13136

  18. Christian Kuhn commented on patch set 9 07/10/21, 09:42

    ActionController.php:403 Reply

    See https://review.typo3.org/c/Packages/TYPO3.CMS/+/65646 - Alex declared this for validators in general at a different point already in v11.0. This change here is just a follow-up picking up another place which https://review.typo3.org/c/Packages/TYPO3.CMS/+/65646 didn't catch. Imho fine.

    GenericViewResolver.php:38 Reply

    I run into trouble at places where ObjectManager->get() instantiated these classes, since OM has no 'alias' for ContainerInterface and the service injection of container then failed. This happened in particular with the styleguide backend module - styleguide has no Services.yaml, yet and the backend controller extends extbase backendController. I saw your change to register ContainerInterface / container recently (OM receives all aliases in a compilerPass loop), so maybe your change fixed that, but I did not re-test again. But the "OM can't inject containerInerface thing was the reason i used getContainer()" in a couple of places.

    Query.php:124 Reply

    see my other comment, do that only if it works with OM.

    QueryFactory.php:55 Reply

    Added this in case anyone registered a different alias. But yeah, compiling should fail if that alias isn't available. So yeah, that if seems obsolete and should be possible to drop together with else.

    PropertyMapper.php:82 Reply

    ok. yeah. should be easily do-able, too.

    ObjectConverter.php:256 Reply

    I wasn't sure here and picked the straight path saying 'no manual constructor arguments for these mapped objects'. The typical use-case for the ObjectConverter is if a form is mapped to some object (like "demand" in beuser). Those have the typical get/set methods. People don't seem to know that properties could be hand over as __construct arguments, extbase then finds them and maps them if the argument name matches. I'd thus argue this is a rather unknown, pretty ugly, and highly magic-driven feature and tried to drop that rather silently ^^ Now that you point it out, I still think we could do that, but not 100% sure anymore. Maybe Alex could also state his opinion on this topic? My point is: everyone use inject* stuff in extbase everywhere and not many people use stuff like this special construct argument mapping ... i'd thus rather drop the latter.
  19. Christian Kuhn commented on patch set 9 07/21/21, 16:07

    ActionController.php:403 Reply

    Done

    GenericViewResolver.php:38 Reply

    QueryFactory.php:55 Reply

    Done

    PropertyMapper.php:82 Reply

    Done

    ObjectConverter.php:256 Reply

    will keep solution as is.
  20. Christian Kuhn uploaded patch set 10 07/21/21, 16:07

  21. core-ci voted on patch set 10 V +1 07/21/21, 16:19 Core CI is happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/13634

  22. Benni Mack voted on patch set 10 V +1 CR +1 07/22/21, 13:45

  23. Jochen Roth voted on patch set 10 V +1 CR +1 07/22/21, 14:43

  24. Christian Kuhn voted on patch set 10 V +2 CR +2 07/22/21, 14:53

  25. Christian Kuhn merged patch set 11 07/22/21, 14:54