From 3c6d295a8f4d21ca34fb82ced2dcf3db1ae1b435 Mon Sep 17 00:00:00 2001
From: Benjamin Franzke <bfr@qbus.de>
Date: Sun, 26 Apr 2020 23:33:01 +0200
Subject: [PATCH] [TASK] Provide dependency injection configuration for extbase
 DataMapper
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The extbase DataMapper was changed to use constructor based
dependency injection with change #87305. The argument $query
(of type QueryInterface) was set to a nullable
and way therefore ignored by the Extbase ObjectManager.

This class is currently only used via the Extbase ObjectManager
in core. It was therefore excluded from the symfony dependency
injection and therefore never fataled during symfony DI
container build.

Symfony DI does – in contrast to extbase DI – inject nullable
constructor arguments.
That means:
Once core or an extension starts to inject this service,
injection will fail, as QueryInterface points to the Query object
which is not autowirable. (see exception below)

Note: While it is not supported that extensions inject
this internal service, we still fix this case, because the
exception is a) hard to debug und b) core may inject it in
future.

The service is also declarted to be a prototype (shared: false) as it may
contain state, as set via `setQuery`.

[1] exception thrown by symfonyduring DI compilation:
    Symfony\Component\DependencyInjection\Exception\RuntimeException:
    Cannot autowire service "TYPO3\CMS\Extbase\Persistence\Generic\Query":
    argument "$type" of method "__construct()" has no type-hint,
    you should configure its value explicitly.

Releases: master
Resolves: #91200
Related: #87305
Change-Id: I58b1cff94136a4170fb7e6712470069a141940b7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64319
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Sebastian Fischer <typo3@evoweb.de>
Tested-by: Alexander Schnitzler <git@alexanderschnitzler.de>
Reviewed-by: Sebastian Fischer <typo3@evoweb.de>
Reviewed-by: Alexander Schnitzler <git@alexanderschnitzler.de>
---
 typo3/sysext/extbase/Configuration/Services.yaml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/typo3/sysext/extbase/Configuration/Services.yaml b/typo3/sysext/extbase/Configuration/Services.yaml
index d0c5dfda66bc..2e592c50e129 100644
--- a/typo3/sysext/extbase/Configuration/Services.yaml
+++ b/typo3/sysext/extbase/Configuration/Services.yaml
@@ -35,6 +35,11 @@ services:
   TYPO3\CMS\Extbase\Persistence\Generic\QueryResult: ~
   TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings: ~
 
+  TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper:
+    shared: false
+    arguments:
+      $query: null
+
   cache.extbase:
     class: TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
     factory: ['@TYPO3\CMS\Core\Cache\CacheManager', 'getCache']
-- 
GitLab