‪TYPO3CMS  10.4
EmConfUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 
26 class EmConfUtility implements SingletonInterface
27 {
35  public function includeEmConf(string $extensionKey, array $extension)
36  {
37  $_EXTKEY = $extensionKey;
38  if (!empty($extension['packagePath'])) {
39  $path = $extension['packagePath'] . 'ext_emconf.php';
40  } else {
41  $path = ‪Environment::getPublicPath() . '/' . $extension['siteRelPath'] . 'ext_emconf.php';
42  }
43  ‪$EM_CONF = null;
44  if (file_exists($path)) {
45  include $path;
46  if (is_array(‪$EM_CONF[$_EXTKEY])) {
47  return ‪$EM_CONF[$_EXTKEY];
48  }
49  }
50  return false;
51  }
52 
62  public function constructEmConf(array $extensionData, Extension $extension = null)
63  {
64  if (is_object($extension) && empty($extensionData['EM_CONF']['constraints'])) {
65  $extensionData['EM_CONF']['constraints'] = unserialize($extension->getSerializedDependencies(), ['allowed_classes' => false]);
66  }
67  $emConf = $this->fixEmConf($extensionData['EM_CONF']);
68  $emConf = var_export($emConf, true);
69  $code = '<?php
70 
71 /***************************************************************
72  * Extension Manager/Repository config file for ext "' . $extensionData['extKey'] . '".
73  *
74  * Auto generated ' . date('d-m-Y H:i') . '
75  *
76  * Manual updates:
77  * Only the data in the array - everything else is removed by next
78  * writing. "version" and "dependencies" must not be touched!
79  ***************************************************************/
80 
81 $EM_CONF[$_EXTKEY] = ' . $emConf . ';
82 
83 ';
84  return $code;
85  }
86 
93  protected function fixEmConf(array $emConf)
94  {
95  if (
96  !isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])
97  || !isset($emConf['constraints']['conflicts']) || !isset($emConf['constraints']['suggests'])
98  ) {
99  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])) {
100  $emConf['constraints']['depends'] = $this->stringToDependency($emConf['dependencies'] ?? '');
101  if (isset($emConf['PHP_version']) && (string)$emConf['PHP_version'] !== '') {
102  $emConf['constraints']['depends']['php'] = $emConf['PHP_version'];
103  }
104  if (isset($emConf['TYPO3_version']) && (string)$emConf['TYPO3_version'] !== '') {
105  $emConf['constraints']['depends']['typo3'] = $emConf['TYPO3_version'];
106  }
107  }
108  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['conflicts'])) {
109  $emConf['constraints']['conflicts'] = $this->stringToDependency($emConf['conflicts'] ?? '');
110  }
111  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['suggests'])) {
112  $emConf['constraints']['suggests'] = [];
113  }
114  }
115 
116  // Remove TER v1-style entries
117  unset($emConf['dependencies']);
118  unset($emConf['conflicts']);
119  unset($emConf['suggests']);
120  unset($emConf['private']);
121  unset($emConf['download_password']);
122  unset($emConf['TYPO3_version']);
123  unset($emConf['PHP_version']);
124  unset($emConf['internal']);
125  unset($emConf['module']);
126  unset($emConf['loadOrder']);
127  unset($emConf['lockType']);
128  unset($emConf['createDirs']);
129  unset($emConf['shy']);
130  unset($emConf['priority']);
131  unset($emConf['modify_tables']);
132  unset($emConf['CGLcompliance']);
133  unset($emConf['CGLcompliance_note']);
134 
135  return $emConf;
136  }
137 
149  protected function stringToDependency($dependency)
150  {
151  $constraint = [];
152  if (is_string($dependency) && $dependency !== '') {
153  $dependency = explode(',', $dependency);
154  foreach ($dependency as $v) {
155  $constraint[$v] = '';
156  }
157  }
158  return $constraint;
159  }
160 }
‪TYPO3\CMS\Extensionmanager\Utility
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:180
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:23
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:40
‪$EM_CONF
‪$EM_CONF[$_EXTKEY]
Definition: ext_emconf.php:3