From 6a650d608f8b01ba1030ec30c36202bde93881dd Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Mon, 28 May 2018 20:20:07 +0200
Subject: [PATCH] [TASK] Deprecate PhpOptionsUtility

The utility class was thinned out in the last TYPO3
versions and now is only used in EXT:install.

The functionality can be moved into EXT:install,
and PhpOptionsUtility can be deprecated, marked
as deprecated and awaiting removal in TYPO3 v10.0.

Resolves: #85102
Releases: master
Change-Id: Ie45720ad70cd2bdd2949553c94fcec15806cb458
Reviewed-on: https://review.typo3.org/57071
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../Classes/Utility/PhpOptionsUtility.php     |  4 +++
 .../Deprecation-85102-PhpOptionsUtility.rst   | 34 +++++++++++++++++++
 .../Classes/Service/SessionService.php        | 23 ++++++++++++-
 .../ExtensionScanner/Php/ClassNameMatcher.php |  5 +++
 .../Php/MethodCallStaticMatcher.php           | 14 ++++++++
 5 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Deprecation-85102-PhpOptionsUtility.rst

diff --git a/typo3/sysext/core/Classes/Utility/PhpOptionsUtility.php b/typo3/sysext/core/Classes/Utility/PhpOptionsUtility.php
index 4d04233b9667..ee6fc51fa1e6 100644
--- a/typo3/sysext/core/Classes/Utility/PhpOptionsUtility.php
+++ b/typo3/sysext/core/Classes/Utility/PhpOptionsUtility.php
@@ -23,9 +23,11 @@ class PhpOptionsUtility
      * Check if php session.auto_start is enabled
      *
      * @return bool TRUE if session.auto_start is enabled, FALSE if disabled
+     * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.0. Use custom filter_var()/ini_get() functionality yourself.
      */
     public static function isSessionAutoStartEnabled()
     {
+        trigger_error('The PhpOptionsUtility class will be removed in TYPO3 v10.0. Use custom filter_var()/ini_get() functionality yourself.', E_USER_DEPRECATED);
         return self::getIniValueBoolean('session.auto_start');
     }
 
@@ -34,9 +36,11 @@ class PhpOptionsUtility
      *
      * @param string $configOption
      * @return bool TRUE if the given option is enabled, FALSE if disabled
+     * @deprecated since TYPO3 v9.3, will be removed in TYPO3 v10.0. Use custom filter_var()/ini_get() functionality yourself.
      */
     public static function getIniValueBoolean($configOption)
     {
+        trigger_error('The PhpOptionsUtility class will be removed in TYPO3 v10.0. Use custom filter_va()/ini_get() functionality yourself.', E_USER_DEPRECATED);
         return filter_var(ini_get($configOption), FILTER_VALIDATE_BOOLEAN, [FILTER_REQUIRE_SCALAR, FILTER_NULL_ON_FAILURE]);
     }
 }
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85102-PhpOptionsUtility.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85102-PhpOptionsUtility.rst
new file mode 100644
index 000000000000..f3e90922771c
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-85102-PhpOptionsUtility.rst
@@ -0,0 +1,34 @@
+.. include:: ../../Includes.txt
+
+=======================================
+Deprecation: #85102 - PhpOptionsUtility
+=======================================
+
+See :issue:`85102`
+
+Description
+===========
+
+The PHP class :php:`\TYPO3\CMS\Core\Utility\PhpOptionsUtility` has been marked as deprecated.
+
+The only purpose for this class was to check for available session handling in the installer.
+
+
+Impact
+======
+
+Calling any method in this class will trigger deprecation warning.
+
+
+Affected Installations
+======================
+
+Installations checking for session handling in custom extensions.
+
+
+Migration
+=========
+
+Implement the :php:`filter_var()` and :php:`ini_get()` used in the PhpOptionsUtility wrapper yourself.
+
+.. index:: PHP-API, FullyScanned, ext:core
\ No newline at end of file
diff --git a/typo3/sysext/install/Classes/Service/SessionService.php b/typo3/sysext/install/Classes/Service/SessionService.php
index 3bf73488d779..d5eec31fffae 100644
--- a/typo3/sysext/install/Classes/Service/SessionService.php
+++ b/typo3/sysext/install/Classes/Service/SessionService.php
@@ -80,7 +80,7 @@ class SessionService implements SingletonInterface
         ini_set('session.gc_probability', (string)100);
         ini_set('session.gc_divisor', (string)100);
         ini_set('session.gc_maxlifetime', (string)$this->expireTimeInMinutes * 2 * 60);
-        if (\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSessionAutoStartEnabled()) {
+        if ($this->isSessionAutoStartEnabled()) {
             $sessionCreationError = 'Error: session.auto-start is enabled.<br />';
             $sessionCreationError .= 'The PHP option session.auto-start is enabled. Disable this option in php.ini or .htaccess:<br />';
             $sessionCreationError .= '<pre>php_value session.auto_start Off</pre>';
@@ -523,4 +523,25 @@ class SessionService implements SingletonInterface
     {
         session_write_close();
     }
+
+    /**
+     * Check if php session.auto_start is enabled
+     *
+     * @return bool TRUE if session.auto_start is enabled, FALSE if disabled
+     */
+    protected function isSessionAutoStartEnabled()
+    {
+        return $this->getIniValueBoolean('session.auto_start');
+    }
+
+    /**
+     * Cast an on/off php ini value to boolean
+     *
+     * @param string $configOption
+     * @return bool TRUE if the given option is enabled, FALSE if disabled
+     */
+    protected function getIniValueBoolean($configOption)
+    {
+        return filter_var(ini_get($configOption), FILTER_VALIDATE_BOOLEAN, [FILTER_REQUIRE_SCALAR, FILTER_NULL_ON_FAILURE]);
+    }
 }
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php
index f4288c1ee388..691ff43080b7 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php
@@ -674,4 +674,9 @@ return [
             'Deprecation-84411-TypoScriptReferenceLoaderRenamedToTypoScriptReferenceController.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Utility\PhpOptionsUtility' => [
+        'restFiles' => [
+            'Deprecation-85102-PhpOptionsUtility.rst',
+        ],
+    ],
 ];
diff --git a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
index 580413cb6f7a..a47d5faae27d 100644
--- a/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
+++ b/typo3/sysext/install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php
@@ -582,4 +582,18 @@ return [
             'Deprecation-85086-GeneralUtilityArrayToLogString.rst',
         ],
     ],
+    'TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSessionAutoStartEnabled' => [
+        'numberOfMandatoryArguments' => 0,
+        'maximumNumberOfArguments' => 0,
+        'restFiles' => [
+            'Deprecation-85102-PhpOptionsUtility.rst',
+        ],
+    ],
+    'TYPO3\CMS\Core\Utility\PhpOptionsUtility::getIniValueBoolean' => [
+        'numberOfMandatoryArguments' => 1,
+        'maximumNumberOfArguments' => 1,
+        'restFiles' => [
+            'Deprecation-85102-PhpOptionsUtility.rst',
+        ],
+    ],
 ];
-- 
GitLab