Skip to content

Commit

Permalink
[!!!][TASK] Do not rely on global variables for ext_*.php files
Browse files Browse the repository at this point in the history
ext_tables.php, ext_localconf.php and all Configuration/TCA/*.php
do not have global scope anymore.

Thus, it is necessary to use
$GLOBALS['TYPO3_CONF_VARS'] instead of $TYPO3_CONF_VARS

Also, $_EXTKEY and $_EXTCONF are gone in these files.

Resolves: #87483
Releases: master
Change-Id: I2c33c696151ace8596cbc9a59a43ef188de26b9c
Reviewed-on: https://review.typo3.org/59300
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <noreply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
bmack authored and maddy2101 committed Jan 18, 2019
1 parent 121ca20 commit 313a500
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 73 deletions.
2 changes: 1 addition & 1 deletion typo3/sysext/backend/Classes/Template/DocumentTemplate.php
Expand Up @@ -642,7 +642,7 @@ public function getSkinStylesheetDirectories()
foreach ($GLOBALS['TBE_STYLES']['skins'] as $skinExtKey => $skin) {
$skinStylesheetDirs = $this->stylesheetsSkins;
// Skins can add custom stylesheetDirectories using
// $GLOBALS['TBE_STYLES']['skins'][$_EXTKEY]['stylesheetDirectories']
// $GLOBALS['TBE_STYLES']['skins']['your_extension_key']['stylesheetDirectories']
if (is_array($skin['stylesheetDirectories'])) {
$skinStylesheetDirs = array_merge($skinStylesheetDirs, $skin['stylesheetDirectories']);
}
Expand Down
34 changes: 0 additions & 34 deletions typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
Expand Up @@ -1443,18 +1443,9 @@ public static function loadExtLocalconf($allowCaching = true, FrontendInterface
*/
protected static function loadSingleExtLocalconfFiles()
{
// This is the main array meant to be manipulated in the ext_localconf.php files
// In general it is recommended to not rely on it to be globally defined in that
// scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
// Nevertheless we define it here as global for backwards compatibility.
global $TYPO3_CONF_VARS;
foreach (static::$packageManager->getActivePackages() as $package) {
$extLocalconfPath = $package->getPackagePath() . 'ext_localconf.php';
if (@file_exists($extLocalconfPath)) {
// $_EXTKEY and $_EXTCONF are available in ext_localconf.php
// and are explicitly set in cached file as well
$_EXTKEY = $package->getPackageKey();
$_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
require $extLocalconfPath;
}
}
Expand All @@ -1473,8 +1464,6 @@ protected static function createExtLocalconfCacheEntry(FrontendInterface $codeCa
$phpCodeToCache[] = ' * Compiled ext_localconf.php cache file';
$phpCodeToCache[] = ' */';
$phpCodeToCache[] = '';
$phpCodeToCache[] = 'global $TYPO3_CONF_VARS, $T3_SERVICES, $T3_VAR;';
$phpCodeToCache[] = '';
// Iterate through loaded extensions and add ext_localconf content
foreach (static::$packageManager->getActivePackages() as $package) {
$extensionKey = $package->getPackageKey();
Expand All @@ -1486,10 +1475,6 @@ protected static function createExtLocalconfCacheEntry(FrontendInterface $codeCa
$phpCodeToCache[] = ' * File: ' . $extLocalconfPath;
$phpCodeToCache[] = ' */';
$phpCodeToCache[] = '';
// Set $_EXTKEY and $_EXTCONF for this extension
$phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
$phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY] ?? null;';
$phpCodeToCache[] = '';
// Add ext_localconf.php content of extension
$phpCodeToCache[] = trim(file_get_contents($extLocalconfPath));
$phpCodeToCache[] = '';
Expand Down Expand Up @@ -1691,20 +1676,10 @@ public static function loadExtTables($allowCaching = true)
*/
protected static function loadSingleExtTablesFiles()
{
// In general it is recommended to not rely on it to be globally defined in that
// scope, but we can not prohibit this without breaking backwards compatibility
global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
global $PAGES_TYPES, $TBE_STYLES;
global $_EXTKEY;
// Load each ext_tables.php file of loaded extensions
foreach (static::$packageManager->getActivePackages() as $package) {
$extTablesPath = $package->getPackagePath() . 'ext_tables.php';
if (@file_exists($extTablesPath)) {
// $_EXTKEY and $_EXTCONF are available in ext_tables.php
// and are explicitly set in cached file as well
$_EXTKEY = $package->getPackageKey();
$_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
require $extTablesPath;
}
}
Expand All @@ -1721,11 +1696,6 @@ protected static function createExtTablesCacheEntry()
$phpCodeToCache[] = ' * Compiled ext_tables.php cache file';
$phpCodeToCache[] = ' */';
$phpCodeToCache[] = '';
$phpCodeToCache[] = 'global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;';
$phpCodeToCache[] = 'global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;';
$phpCodeToCache[] = 'global $PAGES_TYPES, $TBE_STYLES;';
$phpCodeToCache[] = 'global $_EXTKEY;';
$phpCodeToCache[] = '';
// Iterate through loaded extensions and add ext_tables content
foreach (static::$packageManager->getActivePackages() as $package) {
$extensionKey = $package->getPackageKey();
Expand All @@ -1737,10 +1707,6 @@ protected static function createExtTablesCacheEntry()
$phpCodeToCache[] = ' * File: ' . $extTablesPath;
$phpCodeToCache[] = ' */';
$phpCodeToCache[] = '';
// Set $_EXTKEY and $_EXTCONF for this extension
$phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
$phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY] ?? null;';
$phpCodeToCache[] = '';
// Add ext_tables.php content of extension
$phpCodeToCache[] = trim(file_get_contents($extTablesPath));
$phpCodeToCache[] = '';
Expand Down
Expand Up @@ -1333,6 +1333,9 @@ The following features have been removed:
* The array key :php:`uploadfolder` in extensions :php:`ext_emconf.php` files is obsolete and ignored.
* Standalone install tool entry point :file:`typo3/install/index.php` has been dropped, use :file:`typo3/install.php` instead
* INCLUDE_TYPOSCRIPT statements in typoscript using a `.txt` ending for a file that ends with `.typoscript` does not work any longer
* These variables are no longer declared in :file:`ext_tables.php` and :file:`ext_localconf.php` files: :php:`$_EXTKEY`, :php:`$_EXTCONF`,
:php:`T3_SERVICES`, :php:`T3_VAR`, :php:`TYPO3_CONF_VARS`, :php:`TBE_MODULES`, :php:`TBE_MODULES_EXT`, :php:`TCA`,
:php:`PAGES_TYPES`, :php:`TBE_STYLES`


The following database tables have been removed:
Expand Down
Expand Up @@ -4,10 +4,10 @@
/**
* Add labels for context sensitive help (CSH)
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('_MOD_web_BlogExampleTxBlogexampleM1', 'EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_csh.xml');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('_MOD_web_BlogExampleTxBlogexampleM1', 'EXT:blog_example/Resources/Private/Language/locallang_csh.xml');

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin($_EXTKEY, 'Blogs', 'Blog listing');
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin('blog_example', 'Blogs', 'Blog listing');

// Categorize Blog,Post records
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable($_EXTKEY, 'tx_blogexample_domain_model_blog');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable($_EXTKEY, 'tx_blogexample_domain_model_post');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable('blog_example', 'tx_blogexample_domain_model_blog');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable('blog_example', 'tx_blogexample_domain_model_post');
20 changes: 0 additions & 20 deletions typo3/sysext/install/Classes/Controller/UpgradeController.php
Expand Up @@ -1099,16 +1099,7 @@ protected function coreUpdateGetVersionToHandle(ServerRequestInterface $request)
protected function extensionCompatTesterLoadExtLocalconfForExtension(Package $package)
{
$extLocalconfPath = $package->getPackagePath() . 'ext_localconf.php';
// This is the main array meant to be manipulated in the ext_localconf.php files
// In general it is recommended to not rely on it to be globally defined in that
// scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
// Nevertheless we define it here as global for backwards compatibility.
global $TYPO3_CONF_VARS;
if (@file_exists($extLocalconfPath)) {
// $_EXTKEY and $_EXTCONF are available in ext_localconf.php
// and are explicitly set in cached file as well
$_EXTKEY = $package->getPackageKey();
$_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
require $extLocalconfPath;
}
}
Expand All @@ -1122,18 +1113,7 @@ protected function extensionCompatTesterLoadExtLocalconfForExtension(Package $pa
protected function extensionCompatTesterLoadExtTablesForExtension(Package $package)
{
$extTablesPath = $package->getPackagePath() . 'ext_tables.php';
// In general it is recommended to not rely on it to be globally defined in that
// scope, but we can not prohibit this without breaking backwards compatibility
global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
global $PAGES_TYPES, $TBE_STYLES;
global $_EXTKEY;
// Load each ext_tables.php file of loaded extensions
$_EXTKEY = $package->getPackageKey();
if (@file_exists($extTablesPath)) {
// $_EXTKEY and $_EXTCONF are available in ext_tables.php
// and are explicitly set in cached file as well
$_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
require $extTablesPath;
}
}
Expand Down
9 changes: 0 additions & 9 deletions typo3/sysext/install/Classes/Service/LoadTcaService.php
Expand Up @@ -89,11 +89,6 @@ public function loadExtensionTablesWithoutMigration()
*/
public function loadSingleExtTablesFile(string $extensionKey)
{
global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
global $PAGES_TYPES, $TBE_STYLES;
global $_EXTKEY;

$packageManager = GeneralUtility::makeInstance(PackageManager::class);
try {
$package = $packageManager->getPackage($extensionKey);
Expand All @@ -107,10 +102,6 @@ public function loadSingleExtTablesFile(string $extensionKey)
$extTablesPath = $package->getPackagePath() . 'ext_tables.php';
// Load ext_tables.php file of the extension
if (@file_exists($extTablesPath)) {
// $_EXTKEY and $_EXTCONF are available in ext_tables.php
// and are explicitly set in cached file as well
$_EXTKEY = $extensionKey;
$_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
require $extTablesPath;
}
}
Expand Down
Expand Up @@ -275,9 +275,9 @@ task. Let's look at one of the base classes declaration as an example:

// Add caching framework garbage collection task
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks'][\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/locallang.xlf:cachingFrameworkGarbageCollection.name',
'description' => 'LLL:EXT:' . $_EXTKEY . '/locallang.xlf:cachingFrameworkGarbageCollection.description',
'extension' => 'your_extension_key,
'title' => 'LLL:EXT:your_extension_key/locallang.xlf:cachingFrameworkGarbageCollection.name',
'description' => 'LLL:EXT:your_extension_key/locallang.xlf:cachingFrameworkGarbageCollection.description',
'additionalFields' => \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionAdditionalFieldProvider::class
);

Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/t3editor/Resources/Private/tsref.xml
Expand Up @@ -679,7 +679,7 @@ Note: TYPO3 comes with a built-in concatenation handler, but you can also regist
Example:
$GLOBALS['TYPO3_CONF_VARS']['FE']['jsConcatenateHandler'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Classes/class.tx_myext_jsConcatenateHandler.php:tx_myext_jsConcatenateHandler->concatenateJs';]]></description>
$GLOBALS['TYPO3_CONF_VARS']['FE']['jsConcatenateHandler'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('myext') . 'Classes/class.tx_myext_jsConcatenateHandler.php:tx_myext_jsConcatenateHandler->concatenateJs';]]></description>
<default><![CDATA[false]]></default>
</property>
<property name="concatenateCss" type="boolean">
Expand All @@ -693,7 +693,7 @@ Note: TYPO3 comes with a built-in concatenation handler, but you can also regist
Example:
$GLOBALS['TYPO3_CONF_VARS']['FE']['cssConcatenateHandler'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Classes/class.tx_myext_cssConcatenateHandler.php:tx_myext_cssConcatenateHandler->concatenateCss';]]></description>
$GLOBALS['TYPO3_CONF_VARS']['FE']['cssConcatenateHandler'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('myext') . 'Classes/class.tx_myext_cssConcatenateHandler.php:tx_myext_cssConcatenateHandler->concatenateCss';]]></description>
<default><![CDATA[false]]></default>
</property>
<property name="sendCacheHeaders" type="boolean">
Expand Down

0 comments on commit 313a500

Please sign in to comment.