From 9caf10ee38cb8015288f792530100114951ae000 Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Tue, 30 Nov 2021 13:24:18 +0100
Subject: [PATCH] [!!!][TASK] Remove extbase EnvironmentService

Resolves: #96159
Related: #92494
Releases: main
Change-Id: I330165bd268f9e9eb011b6ee5bee208f446aed6f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72403
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
---
 ...g-96107-DeprecatedFunctionalityRemoved.rst |  1 +
 .../Classes/Service/EnvironmentService.php    | 87 -------------------
 .../extbase/Classes/ServiceProvider.php       | 10 ---
 .../ExtensionScanner/Php/ClassNameMatcher.php |  1 +
 4 files changed, 2 insertions(+), 97 deletions(-)
 delete mode 100644 typo3/sysext/extbase/Classes/Service/EnvironmentService.php

diff --git a/typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96107-DeprecatedFunctionalityRemoved.rst b/typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96107-DeprecatedFunctionalityRemoved.rst
index 0b12e49fc498..7265965d8289 100644
--- a/typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96107-DeprecatedFunctionalityRemoved.rst
+++ b/typo3/sysext/core/Documentation/Changelog/12.0/Breaking-96107-DeprecatedFunctionalityRemoved.rst
@@ -27,6 +27,7 @@ The following PHP classes that have previously been marked as deprecated for v11
 - :php:`\TYPO3\CMS\Extbase\Domain\Repository\CategoryRepository`
 - :php:`\TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository`
 - :php:`\TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository`
+- :php:`\TYPO3\CMS\Extbase\Service\EnvironmentService`
 
 The following PHP interfaces that have previously been marked as deprecated for v11 and were now removed:
 
diff --git a/typo3/sysext/extbase/Classes/Service/EnvironmentService.php b/typo3/sysext/extbase/Classes/Service/EnvironmentService.php
deleted file mode 100644
index cf7893a6cb1c..000000000000
--- a/typo3/sysext/extbase/Classes/Service/EnvironmentService.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-namespace TYPO3\CMS\Extbase\Service;
-
-use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Http\ApplicationType;
-use TYPO3\CMS\Core\SingletonInterface;
-
-/**
- * Service for determining environment params
- * @internal only to be used within Extbase, not part of TYPO3 Core API.
- * @deprecated since v11.2, will be removed in v12.0.
- */
-class EnvironmentService implements SingletonInterface
-{
-    /**
-     * @var bool|null
-     */
-    protected $isFrontendMode;
-
-    public function __construct()
-    {
-        trigger_error(__CLASS__ . ' will be removed in TYPO3 v12, use the PSR-7 Request and the ApplicationType instead.', E_USER_DEPRECATED);
-    }
-
-    /**
-     * Detects if frontend application has been called.
-     *
-     * @return bool
-     */
-    public function isEnvironmentInFrontendMode(): bool
-    {
-        $this->initialize();
-        if ($this->isFrontendMode !== null) {
-            return $this->isFrontendMode;
-        }
-        // Frontend mode stays false if backend or cli without request object
-        return ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
-            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend();
-    }
-
-    /**
-     * Detects if backend application has been called.
-     *
-     * @return bool
-     */
-    public function isEnvironmentInBackendMode(): bool
-    {
-        return !$this->isEnvironmentInFrontendMode();
-    }
-
-    protected function initialize(): void
-    {
-        if ($this->isFrontendMode !== null) {
-            return;
-        }
-        // Frontend mode stays false if backend or cli without request object
-        $this->isFrontendMode = ($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface
-            && ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend();
-    }
-
-    /**
-     * A helper method for tests to simulate application behavior, should only be used within TYPO3 Core
-     *
-     * @param bool $isFrontendMode
-     * @internal only used for testing purposes and can be removed at any time.
-     */
-    public function setFrontendMode(bool $isFrontendMode): void
-    {
-        $this->isFrontendMode = $isFrontendMode;
-    }
-}
diff --git a/typo3/sysext/extbase/Classes/ServiceProvider.php b/typo3/sysext/extbase/Classes/ServiceProvider.php
index 06433bc958b1..924076a53f1f 100644
--- a/typo3/sysext/extbase/Classes/ServiceProvider.php
+++ b/typo3/sysext/extbase/Classes/ServiceProvider.php
@@ -47,8 +47,6 @@ class ServiceProvider extends AbstractServiceProvider
             Configuration\BackendConfigurationManager::class => [ static::class, 'getBackendConfigurationManager' ],
             Configuration\ConfigurationManager::class => [ static::class, 'getConfigurationManager' ],
             Reflection\ReflectionService::class => [ static::class, 'getReflectionService' ],
-            // @deprecated since v11, will be removed in v12
-            Service\EnvironmentService::class => [ static::class, 'getEnvironmentService' ],
             Service\ExtensionService::class => [ static::class, 'getExtensionService' ],
             Service\ImageService::class => [ static::class, 'getImageService' ],
             Security\Cryptography\HashService::class => [ static::class, 'getHashService' ],
@@ -97,14 +95,6 @@ class ServiceProvider extends AbstractServiceProvider
         return self::new($container, Reflection\ReflectionService::class, [$container->get(CacheManager::class)->getCache('extbase'), $container->get(PackageDependentCacheIdentifier::class)->withPrefix('ClassSchemata')->toString()]);
     }
 
-    /**
-     * @deprecated since v11, will be removed in v12
-     */
-    public static function getEnvironmentService(ContainerInterface $container): Service\EnvironmentService
-    {
-        return self::new($container, Service\EnvironmentService::class);
-    }
-
     public static function getExtensionService(ContainerInterface $container): Service\ExtensionService
     {
         $extensionService = self::new($container, Service\ExtensionService::class);
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php
index cd2948bcd893..2c435d116310 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php
@@ -1624,6 +1624,7 @@ return [
     'TYPO3\CMS\Extbase\Service\EnvironmentService' => [
         'restFiles' => [
             'Deprecation-92494-ExtbaseEnvironmentService.rst',
+            'Breaking-96107-DeprecatedFunctionalityRemoved.rst',
         ],
     ],
     'TYPO3\CMS\Backend\ViewHelpers\ModuleLayoutViewHelper' => [
-- 
GitLab