Review main Merged

63826[TASK] Mark ObjectManager::get deprecated

Alexander Schnitzler CR +2 V +2 Normal +174 −0 updated 04/20/20, 11:58

Commit message

This patch adds an @deprecated annotation to the get
method of the ObjectManager class of Extbase. Both the
core and users use the object manager directly to create
instances of dependencies, often like this:

GeneralUtility::makeInstance(ObjectManager::class)
    ->get(Dependency::class);

This is done to create an instance of an object along with
it's own dependencies. Using the object manager directly
is bad practice. Mandatory dependencies should be injected
via constructor injection while optional dependencies may
be injected via method and property injection. In both
cases however, the underlying object container takes care
of the dependency injection.

This patch intentionally does not add a trigger_error call
as the core itself still is a bad example and uses that
technique itself a lot. Version 11.0 will remove all
such usages and introduce the trigger_error call for user
land code until the object manager is finally removed in
version 12.0.

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Susi Moog +2
    • Oli Bartsch +1
    • Oliver Klee +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Susi Moog +2
    • Daniel Goerz +1
    • Oli Bartsch +1
    • TYPO3com +1 CI

Issues 1

Files 3

Review log 6274

Show 4249 earlier messages
  1. Alexander Schnitzler uploaded patch set 1 03/21/20, 10:35

  2. TYPO3com voted on patch set 1 V +1 03/21/20, 11:01 Completed build in 19m 00s on Sat, 21 Mar, 11:01 AM Test Summary: 72225 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-1537

  3. Alexander Schnitzler wrote 03/21/20, 14:04

    Topic set to extbase
  4. Alexander Schnitzler uploaded patch set 2 03/21/20, 14:13

  5. TYPO3com voted on patch set 2 V -1 03/21/20, 14:24 Completed build in 10m 42s on Sat, 21 Mar, 02:24 PM Test Summary: 72121 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-1542

  6. Georg Ringer commented on patch set 2 CR -1 03/21/20, 15:39

    TBH I really woud like to avoid that for 10, 4 weeks before release. this would mean that is is a lot harder to migrate e.g. command controllers having no deprecations
  7. Tymoteusz Motylewski commented on patch set 2 03/21/20, 19:08

    Would ot be possible to have a rector rule for automatic migration or is the migration not so simple?
  8. Alexander Schnitzler commented on patch set 2 03/21/20, 19:35

    > Patch Set 2: Code-Review-1 > > TBH I really woud like to avoid that for 10, 4 weeks before release. this would mean that is is a lot harder to migrate e.g. command controllers having no deprecations What is the problem with adding the tag? We don't trigger a warning here yet and this is just a friendly reminder for those using that method to think about what they are doing. Using the container directly never was recommended and it's not even necessary. The usage can directly be replaced in user land code and adding a tag creates awareness already that we have proper DI.
  9. Alexander Schnitzler commented on patch set 2 03/21/20, 19:38

    > Patch Set 2: > > Would ot be possible to have a rector rule for automatic migration or is the migration not so simple? Unfortunately the migration is not so easy because we currently use that method for creating both singletons (services) and prototypes. We would need to distinguish between those cases. There are also different possibilites to replace this. constructor, method and property injection. Which to use depends on the environment.
  10. TYPO3com voted on patch set 2 V +1 03/21/20, 19:51 Completed build in 5h 48m 53s on Sat, 21 Mar, 07:51 PM Test Summary: 72231 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-1542

  11. Benni Mack commented on patch set 2 03/22/20, 19:11

    > Patch Set 2: Code-Review-1 > > TBH I really woud like to avoid that for 10, 4 weeks before release. this would mean that is is a lot harder to migrate e.g. command controllers having no deprecations Hey Georg, I think adding a @deprecated tag should be fine, but along with a good description on how to replace it (@alex this is still missing). Removing all usages in TYPO3 v11 will be A LOT of work to actually do a deprecation with trigger_error() during v11. Making developers aware that they can already use Symfony DI via Extbase should be communicated - and I consider this approach useful.
  12. Georg Ringer commented on patch set 2 03/22/20, 20:19

    fine with just a tag, however a rst is of course missing + codescanner
  13. Alexander Schnitzler commented on patch set 2 03/22/20, 20:46

    > Patch Set 2: > > fine with just a tag, however a rst is of course missing + codescanner I am not sure about the scanner just yet. This is more a political decision than a technical. Question is: Do we have a clear migration path we can put into an rst which is found by literally everyone? I am not so confident yet. It's a bit like with the deprecation of switchable controller actions. We want to get rid of it but we don't have a clear path yet. To be, an announcement is good, but I am unsure about that scanner that triggers a lot of people to read that exact rst file, which they probably only do once and I want to make the experience worth it.
  14. Georg Ringer commented on patch set 2 03/23/20, 06:24

    > I am not sure about the scanner just yet. This is more a political decision than a technical. Question is: Do we have a clear migration path we can put into an rst which is found by literally everyone? I am not so confident yet. It's a bit like with the deprecation of switchable controller actions. We want to get rid of it but we don't have a clear path yet. To be, an announcement is good, but I am unsure about that scanner that triggers a lot of people to read that exact rst file, which they probably only do once and I want to make the experience worth it. I am fine with having no scanner but if we don't have a clear upgrade path we can't deprecate it.
  15. Alexander Schnitzler commented on patch set 2 03/23/20, 07:39

    > Patch Set 2: > > > I am not sure about the scanner just yet. This is more a political decision than a technical. Question is: Do we have a clear migration path we can put into an rst which is found by literally everyone? I am not so confident yet. It's a bit like with the deprecation of switchable controller actions. We want to get rid of it but we don't have a clear path yet. To be, an announcement is good, but I am unsure about that scanner that triggers a lot of people to read that exact rst file, which they probably only do once and I want to make the experience worth it. > > I am fine with having no scanner but if we don't have a clear upgrade path we can't deprecate it. Look, it's a bit complicated. We have dependency injection in Extbase for 10 years now. There never was a need to use the object manager directly. In the Extbase context, we provide 3 different approaches. constructor, setter and property injection. It means, just looking at Extbase, we have a clear migration path. But that whole DI topic is bigger since we have core wide DI now. Deprecating the ObjectManager of Extbase has two impacts. One is telling people not to use it directly, the other is: Don't use Extbase DI. I am aiming for the first one with this patch but in the end the deprecation means also the latter. The point I want to make with this patch is to make people aware to avoid usages like those: > GeneralUtility::makeInstance(ObjectManager::class)->get(Service::class). We are doing this now because not using the object manager directly is a necessity to smoothly replace Extbase DI with the core wide DI, without people noticing it or say, people noticing very little. All this has another impact which only hits those that don't understand what a service container is. Those that use the object manager to create prototype instances. If people create models with the object manager, they don't have a clear migration path, becasue they have to learn not to use DI in that context. It possibly means a lot of refactoring on their ends. That is something I can't write a good rst file for now and I probably never can because the migration path depends on the individual use case. However, it's important to tell people: Using the object manager is wrong. It always was, the core was and is a bad example, but nevertheless: Think about a replacement now, even if no deprecation error is triggered yet.
  16. Susi Moog commented on patch set 2 03/23/20, 08:38

    Our use case for this always was: instantiating extbase services from non-extbase context (user functions, hooks etc.) - that's where we used ObjectManager::get.
  17. Alexander Schnitzler commented on patch set 2 03/23/20, 15:41

    > Patch Set 2: > > Our use case for this always was: instantiating extbase services from non-extbase context (user functions, hooks etc.) - that's where we used ObjectManager::get. Alrighty. This statement is true and shows how hard it is to achieve a state in which we are safe to remove the functionality. But at some point we have to start. I'd like to repeat my idea of adding that tag already with a rst file, explaining that the object manager must no longer be used inside the Extbase context where native DI is possible. If we can get that message out there and people start to adjust their code base, 90% of the work is done in between the next 3 years and only the tricky parts are left. We need to move forward and I don't want to be the one who gets hammered with questions and complaints shortly before version 12 updates start in the companies. We have the chance to raise awareness now and imho it's a mistake not to do so. Especially with all the events coming up the second half of 2020 and 2021.
  18. Susi Moog commented on patch set 2 03/24/20, 05:36

    > Patch Set 2: > > > Patch Set 2: > > > > Our use case for this always was: instantiating extbase services from non-extbase context (user functions, hooks etc.) - that's where we used ObjectManager::get. > > Alrighty. This statement is true and shows how hard it is to achieve a state in which we are safe to remove the functionality. But at some point we have to start. > > I'd like to repeat my idea of adding that tag already with a rst file, explaining that the object manager must no longer be used inside the Extbase context where native DI is possible. If we can get that message out there and people start to adjust their code base, 90% of the work is done in between the next 3 years and only the tricky parts are left. > > We need to move forward and I don't want to be the one who gets hammered with questions and complaints shortly before version 12 updates start in the companies. We have the chance to raise awareness now and imho it's a mistake not to do so. Especially with all the events coming up the second half of 2020 and 2021. Fine with me, as long as the rst contains enough info to tell people when migration is possible and how to do it - and when the code they have has to stay as it is for now.
  19. Georg Ringer commented on patch set 2 03/24/20, 07:18

    fully agree to what susi says. I am absolutly fine to get rid of that
  20. Georg Ringer voted on patch set 2 CR 0 03/24/20, 07:18

  21. Oliver Klee voted on patch set 2 CR +1 03/24/20, 09:09

  22. Alexander Schnitzler commented on patch set 2 V -1 03/26/20, 10:22

    I am preparing an rst.
  23. Alexander Schnitzler uploaded patch set 3 03/26/20, 15:44

  24. TYPO3com voted on patch set 3 V +1 03/26/20, 15:58 Completed build in 13m 19s on Thu, 26 Mar, 03:58 PM Test Summary: 73011 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-1775

  25. Alexander Schnitzler commented on patch set 3 CR -1 03/27/20, 14:04

    Still working on that rst. I setup the local rendering chain to verify the output.
  26. Alexander Schnitzler marked it work in progress 03/27/20, 14:04

  27. Alexander Schnitzler uploaded patch set 4 04/02/20, 10:18

  28. TYPO3com voted on patch set 4 V -1 04/02/20, 10:33 Completed build in 13m 42s on Thu, 2 Apr, 10:33 AM Test Summary: 10 of 73742 failed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2088

  29. TYPO3com voted on patch set 4 V +1 04/02/20, 10:55 Completed build in 48m 34s on Thu, 2 Apr, 10:55 AM Test Summary: 73258 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2088

  30. Benni Mack voted on patch set 4 V +1 CR +1 04/06/20, 16:07

  31. Georg Ringer commented on patch set 4 04/07/20, 03:16

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112

    of course it is, it is all about having that deprecated.
  32. Alexander Schnitzler commented on patch set 4 04/07/20, 06:06

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    No, it's not. There is no replacement yet for registerImplementation (for prototypes), therefore that mechanic is not deprecatedyet.
  33. Oliver Klee voted on patch set 4 CR +1 04/07/20, 09:29

  34. Daniel Goerz commented on patch set 4 04/08/20, 19:51

    ObjectManager.php:114 Unresolved

    I think that part of the todo is kind of covered ;)
  35. Daniel Goerz commented on patch set 4 04/08/20, 19:54

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    Maybe let's say it's not yet fully deprecated. Also, this could be an important RST as there will be a proper deprecation in 11, right?
  36. Alexander Schnitzler commented on patch set 4 04/11/20, 07:45

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    So what actual change would you like to see here?
  37. Alexander Schnitzler uploaded patch set 5 04/12/20, 10:28

  38. TYPO3com voted on patch set 5 V +1 04/12/20, 10:41 Completed build in 12m 12s on Sun, 12 Apr, 10:41 AM Test Summary: 73463 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2391

  39. Claus Due voted on patch set 5 CR +1 04/14/20, 13:41

  40. Daniel Goerz commented on patch set 5 04/14/20, 14:23

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    I was just wondring if an important RST ("ObjectManager::get will be deprectad in TYPO3 11" or somethig along those lines) would better reflect what the patch actually does (only marking get() deprecated, not really deprecating it). If you don't like that idea, its perfectly fine with me to keep this as is. I just shared what came to mind first, no strong opinion whatsoever on this.
  41. Alexander Schnitzler commented on patch set 5 04/14/20, 14:40

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply Unresolved

    I neither have any hard feelings about it. I'll let others decide.
  42. Benjamin Franzke voted on patch set 5 V +1 CR +1 04/16/20, 08:40

  43. Benni Mack commented on patch set 5 04/16/20, 08:43

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112

    This is really good. I just had an example in a custom project where people just use ObjectManager->get() to create models. Can we clarify what people should write nowadays (maybe in an example with a Blogpost model or so) instead of ObjectManager->get?
  44. Claus Due commented on patch set 5 04/16/20, 08:57

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    This is a bit unrelated, but the RST should get some attention to wording, syntax and sentence structure - it's a little bit messy currently. I suggest rewriting much of it (also to reduce the size and compactness of information) and at the same time give a concrete example of "prototype" as Benni mentions here.
  45. Alexander Schnitzler commented on patch set 5 04/16/20, 09:01

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    Yep having a native speaker have a look at it would be great. Don't know to what extend you are capable of doing so yourself. Regarding the prototypes: I have the feeling that part is misunderstood. I am not aware of a possibility to override prototypes via DI. If that is possible, we can add an example. I'll ask Benjamin Franzke again. The thing is: If we have a replacement also for prototypes, we could also soft deprecate registerImplementation as well.
  46. Alexander Schnitzler commented on patch set 5 04/16/20, 09:11

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    I talked to Benjamin and we currently don't have a replacement for prototypes such as models. There are ideas and approaches but nothing we should communicate right now.
  47. Benjamin Franzke commented on patch set 5 04/16/20, 09:22

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    To state the alternative approaches: 1) Use XCLASSES – that means model/data-prototype instantiation happens using GeneralUtility::makeInstance() (at least 'make' makes sense then, opposed to `get()`) 2) Use custom autoloaders (as done by EXT:news and EXT:extender to create merged models) – allows simply to use `new FooBarModel`. Option 2) has the nicest syntax, but is a bit out-of-scope for regular extension and there is no defined place where custom autoloaders are supported to be added by extensions (extender and news just put them into ext_localconf.php, but that's a bit of a hack) Option 1) is something we already named in https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/9.5/Deprecation-86270-ExtbaseXclassViaTypoScriptSettings.html > Use XCLASSes configured in :file:`ext_localconf.php` using :php:`$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']`. So, if we really want to name an alternative, then it would be `GeneralUtility::makeInstance` – but the usage of `new` is also fine for custom projects where no overrides will ever be needed. There is no golden rule in this case.
  48. Alexander Schnitzler commented on patch set 5 04/16/20, 10:27

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply

    Just want to add something. I always thought Extbase itself uses the get method to create prototype instances but that isn't really true for models and objects that are passed along alongs. Those are created via getEmptyObject, which bypasses the container (i.e. it doesn't check for existing instances, which is a good thing). BUT: Extbase uses ObjectManager::get for validators, which are still a mixture of prototypes and services. There are dependencies and inner states. So. telling people ObjectManager::get is also deprecated for prototypes is technically right but we don't stick to that rule ourselves (yet).
  49. Oliver Klee voted on patch set 5 CR +1 04/16/20, 12:00

  1. Jonas Eberle voted on patch set 5 V +1 04/18/20, 13:17

  2. Benjamin Franzke commented on patch set 5 CR -1 04/18/20, 16:50

    Code review -1 (although I generally still fully agree with the patch) to prevent an early merge. We discussed in mergers meeting that Anja with try to rephrase the RST.

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:112 Reply Unresolved

    @Anja: To summarize this: Drop this: > Since there is no replacement for that mechanic yet, that usage of :php:`ObjectManager->get()` is not yet officially deprecated. And write something like this instead: For Models you can either decide to simply instantiate via :php:`new`, or if you want to provide support for overwriting models, you may use GeneralUtlity::makeInstance where models can be overwritten via XCLASSes configured in :file:`ext_localconf.php` (configuration variable: :php:`$GLOBALS['TYPO3_CONF_VARS']['SYS']['Objects']`).
  3. Alexander Schnitzler commented on patch set 5 04/19/20, 18:14

    Short update on this one please. What do we do and who does it?
  4. Anja Leichsenring uploaded patch set 6 04/20/20, 06:58

  5. TYPO3com voted on patch set 6 V +1 04/20/20, 07:10 Completed build in 11m 24s on Mon, 20 Apr, 07:10 AM Test Summary: 73627 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2869

  6. Oli Bartsch commented on patch set 6 04/20/20, 07:17

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:24 Unresolved

    Then

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:125

    maybe `about`

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:126

    its

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:147

    `.` missing here.
  7. Susi Moog commented on patch set 6 04/20/20, 07:38

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:25 Unresolved

    this whole paragraph sounds weird, as if I am supposed to use $container->get now. Maybe we should remove / move this part to the bottom after the examples, in general I think it's easier to grasp if you mainly have: "this is what you had before" - "this is what you should do now" and leave the deeper reasoning for the last section.

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:41 Unresolved

    I'd rather say: if you are using code similar to the following example, you should migrate to dependency injection.

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:129

    Again, background can be a nice thing, however, in this case it dilutes the topic. I'd remove the paragraph.

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:133

    This prototype definition sounds weird, especially mixed up with the term model, or is model meant to be an example? If so, then "usual" should probably be "common" or "commonly used".

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:135

    While the information here is valid, I'd rather have a more compact overview of what to migrate in which case. At the moment we are kind of "hiding" the important info in a lot of background and additional info, if you know what I mean.
  8. Anja Leichsenring uploaded patch set 7 04/20/20, 08:55

  9. Anja Leichsenring commented on patch set 7 04/20/20, 08:58

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:125 Reply Unresolved

    rather not. `There is more to it` is a valid phrase and indicates there is more than what was revealed yet.

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:126 Reply

    Done

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:129 Reply

    Done

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:133 Reply

    Ack

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:135 Reply

    Done

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:147 Reply

    Done
  10. Benjamin Franzke commented on patch set 7 V +1 CR +1 04/20/20, 09:04

    Thank you Anja for the RST overhaul.
  11. Daniel Goerz commented on patch set 7 CR -1 04/20/20, 09:09

    I'll proofread, too

    Deprecation-90803-DeprecationOfObjectManagergetInExtbaseContext.rst:12 Unresolved

    To help understand the deprecation of :php:`$objectManager->get(Service::class)` let's first have a look at ....
  12. TYPO3com voted on patch set 7 V +1 04/20/20, 09:13 Completed build in 16m 35s on Mon, 20 Apr, 09:12 AM Test Summary: 73627 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2874

  13. Daniel Goerz uploaded patch set 8 04/20/20, 09:34

  14. Oliver Klee commented on patch set 8 04/20/20, 09:56

    Unresolved

    This either needs to be "will need to have removed" or "must remove".
  15. TYPO3com voted on patch set 8 V -1 04/20/20, 10:01 Completed build in 24m 54s on Mon, 20 Apr, 10:01 AM Test Summary: 73008 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2883

  16. TYPO3com voted on patch set 8 V +1 04/20/20, 10:46 Completed build in 1h 34m 24s on Mon, 20 Apr, 10:46 AM Test Summary: 73627 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2883

  17. Daniel Goerz updated the commit message in patch set 9 04/20/20, 11:06

  18. Daniel Goerz voted on patch set 9 V +1 04/20/20, 11:06

  19. Susi Moog voted on patch set 9 V +1 CR +1 04/20/20, 11:09

  20. TYPO3com voted on patch set 9 V +1 04/20/20, 11:19 Completed build in 12m 24s on Mon, 20 Apr, 11:19 AM Test Summary: 73627 passed Find logs and detail information at https://bamboo.typo3.com/browse/CORE-GTC-2888

  21. Oliver Klee voted on patch set 9 CR +1 04/20/20, 11:22

  22. Oli Bartsch voted on patch set 9 V +1 CR +1 04/20/20, 11:43

  23. Susi Moog voted on patch set 9 V +2 CR +2 04/20/20, 11:58

  24. Georg Ringer voted on patch set 9 V +2 CR +2 04/20/20, 11:58

  25. Susi Moog merged patch set 10 04/20/20, 11:58