[TASK] Reduce ObjectManager usages within ConfigurationManager
authorBenni Mack <benni@typo3.org>
Fri, 7 May 2021 08:44:31 +0000 (10:44 +0200)
committerDaniel Goerz <daniel.goerz@posteo.de>
Sat, 8 May 2021 10:04:49 +0000 (12:04 +0200)
This change removes any objectManager usages within Configuration
Manager.

Resolves: #94093
Releases: master
Change-Id: I24e272e86b28856e19ae86e68735963b9340724c
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69062
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benjamin Franzke <bfr@qbus.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
17 files changed:
typo3/sysext/core/Configuration/Services.yaml
typo3/sysext/extbase/Classes/Configuration/AbstractConfigurationManager.php
typo3/sysext/extbase/Classes/Configuration/ConfigurationManager.php
typo3/sysext/extbase/Classes/Configuration/FrontendConfigurationManager.php
typo3/sysext/extbase/Classes/Persistence/Generic/Typo3QuerySettings.php
typo3/sysext/extbase/Classes/ServiceProvider.php
typo3/sysext/extbase/Classes/Utility/LocalizationUtility.php
typo3/sysext/extbase/Configuration/Services.yaml
typo3/sysext/extbase/Tests/Functional/Service/ExtensionServiceTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryFactoryTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbQueryParserTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Typo3QuerySettingsTest.php
typo3/sysext/fluid/Classes/View/StandaloneView.php
typo3/sysext/fluid/Classes/View/TemplatePaths.php
typo3/sysext/fluid/Classes/ViewHelpers/CObjectViewHelper.php
typo3/sysext/fluid/Classes/ViewHelpers/Format/HtmlViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/CObjectViewHelperTest.php

index 004fa3b..7d349c8 100644 (file)
@@ -116,6 +116,10 @@ services:
     shared: false
     public: true
 
+  TYPO3\CMS\Core\Service\TypoScriptService:
+    shared: false
+    public: true
+
   # FAL security checks for backend users
   TYPO3\CMS\Core\Resource\Security\StoragePermissionsAspect:
     tags:
index 047ab05..4289b8b 100644 (file)
@@ -23,7 +23,6 @@ use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\TypoScript\TypoScriptService;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 use TYPO3\CMS\Extbase\Utility\FrontendSimulatorUtility;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 
@@ -46,19 +45,11 @@ abstract class AbstractConfigurationManager implements SingletonInterface
     protected $configuration = [];
 
     /**
-     * @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
+     * @var ContentObjectRenderer
      */
     protected $contentObject;
 
-    /**
-     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
-     */
-    protected $objectManager;
-
-    /**
-     * @var \TYPO3\CMS\Core\TypoScript\TypoScriptService
-     */
-    protected $typoScriptService;
+    protected TypoScriptService $typoScriptService;
 
     /**
      * name of the extension this Configuration Manager instance belongs to
@@ -81,20 +72,13 @@ abstract class AbstractConfigurationManager implements SingletonInterface
      */
     protected $configurationCache = [];
 
-    /**
-     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
-     * @param \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
-     */
-    public function __construct(
-        ObjectManagerInterface $objectManager,
-        TypoScriptService $typoScriptService
-    ) {
-        $this->objectManager = $objectManager;
+    public function __construct(TypoScriptService $typoScriptService)
+    {
         $this->typoScriptService = $typoScriptService;
     }
 
     /**
-     * @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObject
+     * @param ContentObjectRenderer $contentObject
      */
     public function setContentObject(ContentObjectRenderer $contentObject): void
     {
@@ -102,7 +86,7 @@ abstract class AbstractConfigurationManager implements SingletonInterface
     }
 
     /**
-     * @return \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer|null
+     * @return ContentObjectRenderer|null
      */
     public function getContentObject(): ?ContentObjectRenderer
     {
index 4d0b204..15c2955 100644 (file)
@@ -17,10 +17,10 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Extbase\Configuration;
 
+use Psr\Container\ContainerInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Http\ApplicationType;
 use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;
-use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 
 /**
@@ -32,22 +32,16 @@ use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
  */
 class ConfigurationManager implements ConfigurationManagerInterface
 {
-    /**
-     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
-     */
-    protected $objectManager;
+    private ContainerInterface $container;
 
     /**
-     * @var \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
+     * @var AbstractConfigurationManager
      */
     protected $concreteConfigurationManager;
 
-    /**
-     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
-     */
-    public function __construct(ObjectManagerInterface $objectManager)
+    public function __construct(ContainerInterface $container)
     {
-        $this->objectManager = $objectManager;
+        $this->container = $container;
         $this->initializeConcreteConfigurationManager();
     }
 
@@ -56,9 +50,9 @@ class ConfigurationManager implements ConfigurationManagerInterface
         if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
             && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
         ) {
-            $this->concreteConfigurationManager = $this->objectManager->get(FrontendConfigurationManager::class);
+            $this->concreteConfigurationManager = $this->container->get(FrontendConfigurationManager::class);
         } else {
-            $this->concreteConfigurationManager = $this->objectManager->get(BackendConfigurationManager::class);
+            $this->concreteConfigurationManager = $this->container->get(BackendConfigurationManager::class);
         }
     }
 
@@ -101,8 +95,8 @@ class ConfigurationManager implements ConfigurationManagerInterface
      * Note that this is a low level method and only makes sense to be used by Extbase internally.
      *
      * @param string $configurationType The kind of configuration to fetch - must be one of the CONFIGURATION_TYPE_* constants
-     * @param string $extensionName if specified, the configuration for the given extension will be returned.
-     * @param string $pluginName if specified, the configuration for the given plugin will be returned.
+     * @param string|null $extensionName if specified, the configuration for the given extension will be returned.
+     * @param string|null $pluginName if specified, the configuration for the given plugin will be returned.
      * @throws Exception\InvalidConfigurationTypeException
      * @return array The configuration
      */
index f5f75af..e1b2324 100644 (file)
@@ -22,7 +22,6 @@ use TYPO3\CMS\Core\TypoScript\TypoScriptService;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\Exception\ParseErrorException;
-use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 
 /**
  * A general purpose configuration manager used in frontend mode.
@@ -32,23 +31,13 @@ use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
  */
 class FrontendConfigurationManager extends AbstractConfigurationManager
 {
-    /**
-     * @var \TYPO3\CMS\Core\Service\FlexFormService
-     */
-    protected $flexFormService;
+    protected FlexFormService $flexFormService;
 
-    /**
-     * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
-     * @param \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
-     * @param \TYPO3\CMS\Core\Service\FlexFormService $flexFormService
-     */
     public function __construct(
-        ObjectManagerInterface $objectManager,
         TypoScriptService $typoScriptService,
         FlexFormService $flexFormService
     ) {
-        parent::__construct($objectManager, $typoScriptService);
-
+        parent::__construct($typoScriptService);
         $this->flexFormService = $flexFormService;
     }
 
index 5dae627..56dad48 100644 (file)
@@ -21,13 +21,15 @@ use TYPO3\CMS\Core\Context\LanguageAspect;
 use TYPO3\CMS\Core\Http\ApplicationType;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 
 /**
  * Query settings, reflects the settings unique to TYPO3 CMS.
  */
 class Typo3QuerySettings implements QuerySettingsInterface
 {
+    protected ConfigurationManagerInterface $configurationManager;
+    protected Context $context;
+
     /**
      * Flag if the storage page should be respected for the query.
      *
@@ -87,23 +89,21 @@ class Typo3QuerySettings implements QuerySettingsInterface
      */
     protected $languageUid = 0;
 
-    /**
-     * As long as we use a feature flag ignoreAllEnableFieldsInBe to determine the default behavior, the
-     * initializeObject is responsible for handling that.
-     */
-    public function initializeObject()
-    {
-        /** @var ObjectManager $objectManager */
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-        /** @var ConfigurationManagerInterface $configurationManager */
-        $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
+    public function __construct(
+        Context $context,
+        ConfigurationManagerInterface $configurationManager
+    ) {
+        // QuerySettings should always keep its own Context, as they can differ
+        // Currently this is only used for reading, but might be improved in the future
+        $this->context = clone $context;
+        $this->configurationManager = $configurationManager;
         if (($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
             && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()
-            && $configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
+            && $this->configurationManager->isFeatureEnabled('ignoreAllEnableFieldsInBe')) {
             $this->setIgnoreEnableFields(true);
         }
         /** @var LanguageAspect $languageAspect */
-        $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
+        $languageAspect = $this->context->getAspect('language');
         $this->setLanguageUid($languageAspect->getContentId());
         $this->setLanguageOverlayMode(false);
 
index f45b7de..14a7c73 100644 (file)
@@ -69,16 +69,13 @@ class ServiceProvider extends AbstractServiceProvider
     public static function getBackendConfigurationManager(ContainerInterface $container): Configuration\BackendConfigurationManager
     {
         return self::new($container, Configuration\BackendConfigurationManager::class, [
-            $container->get(Object\ObjectManager::class),
             $container->get(TypoScriptService::class),
         ]);
     }
 
     public static function getConfigurationManager(ContainerInterface $container): Configuration\ConfigurationManager
     {
-        return self::new($container, Configuration\ConfigurationManager::class, [
-            $container->get(Object\ObjectManager::class),
-        ]);
+        return self::new($container, Configuration\ConfigurationManager::class, [$container]);
     }
 
     public static function getReflectionService(ContainerInterface $container): Reflection\ReflectionService
index 3195aa8..b10e183 100644 (file)
@@ -25,7 +25,6 @@ use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 
 /**
  * Localization helper which should be used to fetch localized labels.
@@ -299,10 +298,8 @@ class LocalizationUtility
         if (static::$configurationManager !== null) {
             return static::$configurationManager;
         }
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-        $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
-        static::$configurationManager = $configurationManager;
-        return $configurationManager;
+        static::$configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class);
+        return static::$configurationManager;
     }
 
     /**
index 16e94ca..38d9d8f 100644 (file)
@@ -25,12 +25,18 @@ services:
     alias: TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbBackend
   TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface:
     alias: TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings
+  TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface:
+    alias: TYPO3\CMS\Extbase\Configuration\ConfigurationManager
+    public: true
 
   # Set incompatible classes to null, these require (runtime) parametrized
   # prototype instantiation
   TYPO3\CMS\Extbase\Persistence\Generic\Query: ~
   TYPO3\CMS\Extbase\Persistence\Generic\QueryResult: ~
-  TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings: ~
+
+  TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings:
+    public: true
+    shared: false
 
   TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper:
     public: true
index d0842b2..b177f33 100644 (file)
@@ -18,13 +18,13 @@ declare(strict_types=1);
 namespace TYPO3\CMS\Extbase\Tests\Functional\Service;
 
 use Prophecy\Argument;
+use Psr\Container\ContainerInterface;
 use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
 use TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager;
 use TYPO3\CMS\Extbase\Exception;
-use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
 use TYPO3\CMS\Extbase\Service\ExtensionService;
 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
 
@@ -48,9 +48,9 @@ class ExtensionServiceTest extends FunctionalTestCase
     protected $frontendConfigurationManager;
 
     /**
-     * @var \Prophecy\Prophecy\ObjectProphecy|ObjectManagerInterface
+     * @var \Prophecy\Prophecy\ObjectProphecy|ContainerInterface
      */
-    protected $objectManager;
+    protected $containerProphecy;
 
     protected function setUp(): void
     {
@@ -62,7 +62,7 @@ class ExtensionServiceTest extends FunctionalTestCase
         $this->frontendConfigurationManager = $this->prophesize(FrontendConfigurationManager::class);
         $this->backendConfigurationManager = $this->prophesize(BackendConfigurationManager::class);
 
-        $this->objectManager = $this->prophesize(ObjectManagerInterface::class);
+        $this->containerProphecy = $this->prophesize(ContainerInterface::class);
 
         $this->extensionService = new ExtensionService();
     }
@@ -73,8 +73,8 @@ class ExtensionServiceTest extends FunctionalTestCase
     public function getPluginNameByActionDetectsPluginNameFromGlobalExtensionConfigurationArray()
     {
         $this->frontendConfigurationManager->getConfiguration(Argument::cetera())->willReturn([]);
-        $this->objectManager->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
-        $configurationManager = new ConfigurationManager($this->objectManager->reveal());
+        $this->containerProphecy->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
+        $configurationManager = new ConfigurationManager($this->containerProphecy->reveal());
         $this->extensionService->injectConfigurationManager($configurationManager);
 
         $pluginName = $this->extensionService->getPluginNameByAction('BlogExample', 'Blog', 'testForm');
@@ -90,8 +90,8 @@ class ExtensionServiceTest extends FunctionalTestCase
         $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Service/Fixtures/tt_content_with_single_plugin.xml');
 
         $this->frontendConfigurationManager->getConfiguration(Argument::cetera())->willReturn(['view' => ['defaultPid' => 'auto']]);
-        $this->objectManager->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
-        $configurationManager = new ConfigurationManager($this->objectManager->reveal());
+        $this->containerProphecy->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
+        $configurationManager = new ConfigurationManager($this->containerProphecy->reveal());
         $this->extensionService->injectConfigurationManager($configurationManager);
 
         $expectedResult = 321;
@@ -105,8 +105,8 @@ class ExtensionServiceTest extends FunctionalTestCase
     public function getTargetPidByPluginSignatureReturnsNullIfTargetPidCouldNotBeDetermined()
     {
         $this->frontendConfigurationManager->getConfiguration(Argument::cetera())->willReturn(['view' => ['defaultPid' => 'auto']]);
-        $this->objectManager->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
-        $configurationManager = new ConfigurationManager($this->objectManager->reveal());
+        $this->containerProphecy->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
+        $configurationManager = new ConfigurationManager($this->containerProphecy->reveal());
         $this->extensionService->injectConfigurationManager($configurationManager);
 
         $result = $this->extensionService->getTargetPidByPlugin('ExtensionName', 'SomePlugin');
@@ -120,8 +120,8 @@ class ExtensionServiceTest extends FunctionalTestCase
     {
         $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Service/Fixtures/tt_content_with_two_plugins.xml');
         $this->frontendConfigurationManager->getConfiguration(Argument::cetera())->willReturn(['view' => ['defaultPid' => 'auto']]);
-        $this->objectManager->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
-        $configurationManager = new ConfigurationManager($this->objectManager->reveal());
+        $this->containerProphecy->get(Argument::any())->willReturn($this->frontendConfigurationManager->reveal());
+        $configurationManager = new ConfigurationManager($this->containerProphecy->reveal());
         $this->extensionService->injectConfigurationManager($configurationManager);
 
         $this->expectException(Exception::class);
index 5aa0201..26a4cd9 100644 (file)
@@ -15,6 +15,7 @@
 
 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic;
 
+use TYPO3\CMS\Core\Context\Context;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap;
@@ -103,7 +104,10 @@ class QueryFactoryTest extends UnitTestCase
         $this->dataMap->expects(self::any())->method('getRootLevel')->willReturn($rootLevel);
 
         $query = $this->createMock(QueryInterface::class);
-        $querySettings = new Typo3QuerySettings();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $this->objectManager->expects(self::exactly(2))->method('get')
             ->withConsecutive([QueryInterface::class], [QuerySettingsInterface::class])
             ->willReturnOnConsecutiveCalls($query, $querySettings);
index be8a207..bba8277 100644 (file)
@@ -27,6 +27,7 @@ use TYPO3\CMS\Core\Database\Query\QueryBuilder;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException;
 use TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException;
 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
@@ -291,8 +292,10 @@ class Typo3DbQueryParserTest extends UnitTestCase
         $GLOBALS['TCA'][$table]['ctrl'] = [
             'languageField' => 'sys_language_uid'
         ];
-        /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings|\PHPUnit\Framework\MockObject\MockObject $querySettings */
-        $querySettings = $this->createMock(Typo3QuerySettings::class);
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
         $queryBuilderProphet = $this->getQueryBuilderWithExpressionBuilderProphet();
         $mockTypo3DbQueryParser->_set('queryBuilder', $queryBuilderProphet->reveal());
@@ -310,10 +313,10 @@ class Typo3DbQueryParserTest extends UnitTestCase
         $GLOBALS['TCA'][$table]['ctrl'] = [
             'languageField' => 'sys_language_uid'
         ];
-        /** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings|\PHPUnit\Framework\MockObject\MockObject $querySettings */
-        $querySettings = $this->getMockBuilder(Typo3QuerySettings::class)
-            ->setMethods(['dummy'])
-            ->getMock();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $querySettings->setLanguageUid('1');
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
         $queryBuilderProphet = $this->getQueryBuilderWithExpressionBuilderProphet();
@@ -332,7 +335,10 @@ class Typo3DbQueryParserTest extends UnitTestCase
         $GLOBALS['TCA'][$table]['ctrl'] = [
             'languageField' => 'sys_language_uid'
         ];
-        $querySettings = new Typo3QuerySettings();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
         $queryBuilderProphet = $this->getQueryBuilderWithExpressionBuilderProphet();
         $mockTypo3DbQueryParser->_set('queryBuilder', $queryBuilderProphet->reveal());
@@ -351,7 +357,10 @@ class Typo3DbQueryParserTest extends UnitTestCase
             'languageField' => 'sys_language_uid',
             'delete' => 'deleted'
         ];
-        $querySettings = new Typo3QuerySettings();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $querySettings->setLanguageUid(0);
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
         $queryBuilderProphet = $this->getQueryBuilderWithExpressionBuilderProphet();
@@ -370,7 +379,10 @@ class Typo3DbQueryParserTest extends UnitTestCase
         $GLOBALS['TCA'][$table]['ctrl'] = [
             'languageField' => 'sys_language_uid'
         ];
-        $querySettings = new Typo3QuerySettings();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $querySettings->setLanguageUid(2);
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
         $queryBuilderProphet = $this->getQueryBuilderWithExpressionBuilderProphet();
@@ -390,7 +402,13 @@ class Typo3DbQueryParserTest extends UnitTestCase
             'languageField' => 'sys_language_uid',
             'transOrigPointerField' => 'l10n_parent'
         ];
-        $querySettings = new Typo3QuerySettings();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
+        $querySettings->setIgnoreEnableFields(true);
+        $querySettings->setIncludeDeleted(true);
+        $querySettings->setLanguageOverlayMode(true);
         $querySettings->setLanguageUid(2);
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
 
@@ -414,8 +432,14 @@ class Typo3DbQueryParserTest extends UnitTestCase
             'transOrigPointerField' => 'l10n_parent',
             'delete' => 'deleted'
         ];
-        $querySettings = new Typo3QuerySettings();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $querySettings->setLanguageUid(2);
+        $querySettings->setIgnoreEnableFields(true);
+        $querySettings->setIncludeDeleted(true);
+        $querySettings->setLanguageOverlayMode(true);
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
         $queryBuilderProphet = $this->getQueryBuilderProphetWithQueryBuilderForSubselect();
         $mockTypo3DbQueryParser->_set('queryBuilder', $queryBuilderProphet->reveal());
@@ -435,8 +459,14 @@ class Typo3DbQueryParserTest extends UnitTestCase
             'transOrigPointerField' => 'l10n_parent',
             'delete' => 'deleted'
         ];
-        $querySettings = new Typo3QuerySettings();
+        $querySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
         $querySettings->setLanguageUid(2);
+        $querySettings->setIgnoreEnableFields(true);
+        $querySettings->setIncludeDeleted(true);
+        $querySettings->setLanguageOverlayMode(true);
         $mockTypo3DbQueryParser = $this->getAccessibleMock(Typo3DbQueryParser::class, ['dummy'], [], '', false);
 
         $queryBuilderProphet = $this->getQueryBuilderProphetWithQueryBuilderForSubselect();
index 49829f3..a1d7de5 100644 (file)
@@ -15,6 +15,8 @@
 
 namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic;
 
+use TYPO3\CMS\Core\Context\Context;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
@@ -35,7 +37,10 @@ class Typo3QuerySettingsTest extends UnitTestCase
     protected function setUp(): void
     {
         parent::setUp();
-        $this->typo3QuerySettings = $this->getAccessibleMock(Typo3QuerySettings::class, ['dummy']);
+        $this->typo3QuerySettings = new Typo3QuerySettings(
+            new Context(),
+            $this->prophesize(ConfigurationManagerInterface::class)->reveal()
+        );
     }
 
     /**
index c27f3b3..8732098 100644 (file)
@@ -18,7 +18,7 @@ namespace TYPO3\CMS\Fluid\View;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Http\ApplicationType;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
 use TYPO3\CMS\Extbase\Mvc\Request;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
@@ -31,11 +31,6 @@ use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
  */
 class StandaloneView extends AbstractTemplateView
 {
-    /**
-     * @var ObjectManager|null
-     */
-    protected $objectManager;
-
     /**
      * Constructor
      *
@@ -45,10 +40,10 @@ class StandaloneView extends AbstractTemplateView
      */
     public function __construct(ContentObjectRenderer $contentObject = null)
     {
-        $this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
+        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
 
-        /** @var ConfigurationManagerInterface $configurationManager */
-        $configurationManager = $this->objectManager->get(ConfigurationManagerInterface::class);
+        // @todo: this needs to be removed in the future
+        $configurationManager = GeneralUtility::getContainer()->get(ConfigurationManager::class);
         if ($contentObject === null) {
             /** @var ContentObjectRenderer $contentObject */
             $contentObject = GeneralUtility::makeInstance(ContentObjectRenderer::class);
@@ -62,10 +57,10 @@ class StandaloneView extends AbstractTemplateView
             $baseUri .= TYPO3_mainDir;
         }
 
-        $request = $this->objectManager->get(Request::class);
+        $request = $objectManager->get(Request::class);
         $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
         $request->setBaseUri($baseUri);
-        $renderingContext = $this->objectManager->get(RenderingContext::class, $this);
+        $renderingContext = $objectManager->get(RenderingContext::class, $this);
         $renderingContext->setRequest($request);
         parent::__construct($renderingContext);
     }
index 12876b0..9a95281 100644 (file)
@@ -21,8 +21,8 @@ use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 
 /**
  * Class TemplatePaths
@@ -59,13 +59,11 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
     }
 
     /**
-     * @return ConfigurationManagerInterface
+     * @return ConfigurationManager
      */
     protected function getConfigurationManager()
     {
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-        $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
-        return $configurationManager;
+        return GeneralUtility::makeInstance(ConfigurationManager::class);
     }
 
     /**
index 5c31b5e..7526578 100644 (file)
@@ -23,7 +23,6 @@ use TYPO3\CMS\Core\Site\SiteFinder;
 use TYPO3\CMS\Core\TimeTracker\TimeTracker;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
 use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
@@ -203,12 +202,10 @@ class CObjectViewHelper extends AbstractViewHelper
         return $content;
     }
 
-    /**
-     * @return ConfigurationManagerInterface
-     */
-    protected static function getConfigurationManager()
+    protected static function getConfigurationManager(): ConfigurationManagerInterface
     {
-        return GeneralUtility::makeInstance(ObjectManager::class)->get(ConfigurationManagerInterface::class);
+        // @todo: this should be replaced by DI once Fluid can handle DI properly
+        return GeneralUtility::getContainer()->get(ConfigurationManagerInterface::class);
     }
 
     /**
index 4fcf7c7..30106f2 100644 (file)
@@ -19,7 +19,6 @@ use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Http\ApplicationType;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
@@ -137,8 +136,7 @@ class HtmlViewHelper extends AbstractViewHelper
         self::$tsfeBackup = $GLOBALS['TSFE'] ?? null;
         $GLOBALS['TSFE'] = new \stdClass();
         $GLOBALS['TSFE']->tmpl = new \stdClass();
-        $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
-        $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
+        $configurationManager = GeneralUtility::makeInstance(ConfigurationManagerInterface::class);
         $GLOBALS['TSFE']->tmpl->setup = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
     }
 
index bbe491b..9f73611 100644 (file)
@@ -18,9 +18,9 @@ declare(strict_types=1);
 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers;
 
 use Prophecy\Argument;
+use Symfony\Component\DependencyInjection\Container;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
-use TYPO3\CMS\Extbase\Object\ObjectManager;
 use TYPO3\CMS\Fluid\ViewHelpers\CObjectViewHelper;
 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
@@ -61,8 +61,17 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         $this->viewHelper = new CObjectViewHelper();
         $this->injectDependenciesIntoViewHelper($this->viewHelper);
 
+        $container = new Container();
         $this->configurationManager = $this->prophesize(ConfigurationManagerInterface::class);
         $this->contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
+        $container->set(ConfigurationManagerInterface::class, $this->configurationManager->reveal());
+        GeneralUtility::setContainer($container);
+    }
+
+    protected function tearDown(): void
+    {
+        GeneralUtility::purgeInstances();
+        parent::tearDown(); // TODO: Change the autogenerated stub
     }
 
     /**
@@ -222,10 +231,8 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         $this->contentObjectRenderer->setCurrentVal('foo')->willReturn();
         $this->contentObjectRenderer->cObjGetSingle('TEXT', $subConfigArray, Argument::any())->willReturn('Hello World');
 
-        $objectManager = $this->prophesize(ObjectManager::class);
-        $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
         GeneralUtility::addInstance(ContentObjectRenderer::class, $this->contentObjectRenderer->reveal());
-        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
+        GeneralUtility::getContainer()->set(ConfigurationManagerInterface::class, $this->configurationManager->reveal());
 
         $actualResult = $this->viewHelper->initializeArgumentsAndRender();
         $expectedResult = 'Hello World';
@@ -240,9 +247,6 @@ class CObjectViewHelperTest extends ViewHelperBaseTestcase
         $this->configurationManager->getConfiguration(Argument::any())->willReturn([]);
         $this->contentObjectRenderer->setCurrentVal(Argument::cetera())->willReturn();
         $this->contentObjectRenderer->cObjGetSingle(Argument::cetera())->willReturn('');
-        $objectManager = $this->prophesize(ObjectManager::class);
-        $objectManager->get(ConfigurationManagerInterface::class)->willReturn($this->configurationManager->reveal());
-        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
         $GLOBALS['TSFE'] = $this->getAccessibleMock(TypoScriptFrontendController::class, ['initCaches'], [], '', false);
     }
 }