‪TYPO3CMS  9.5
EmConfUtility.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 class EmConfUtility implements SingletonInterface
25 {
32  public function includeEmConf(array $extension)
33  {
34  $_EXTKEY = $extension['key'];
35  $path = ‪Environment::getPublicPath() . '/' . $extension['siteRelPath'] . 'ext_emconf.php';
36  ‪$EM_CONF = null;
37  if (file_exists($path)) {
38  include $path;
39  if (is_array(‪$EM_CONF[$_EXTKEY])) {
40  return ‪$EM_CONF[$_EXTKEY];
41  }
42  }
43  return false;
44  }
45 
55  public function constructEmConf(array $extensionData, \‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension = null)
56  {
57  if (is_object($extension) && empty($extensionData['EM_CONF']['constraints'])) {
58  $extensionData['EM_CONF']['constraints'] = unserialize($extension->getSerializedDependencies(), ['allowed_classes' => false]);
59  }
60  $emConf = $this->fixEmConf($extensionData['EM_CONF']);
61  $emConf = var_export($emConf, true);
62  $code = '<?php
63 
64 /***************************************************************
65  * Extension Manager/Repository config file for ext "' . $extensionData['extKey'] . '".
66  *
67  * Auto generated ' . date('d-m-Y H:i') . '
68  *
69  * Manual updates:
70  * Only the data in the array - everything else is removed by next
71  * writing. "version" and "dependencies" must not be touched!
72  ***************************************************************/
73 
74 $EM_CONF[$_EXTKEY] = ' . $emConf . ';
75 
76 ';
77  return $code;
78  }
79 
86  public function fixEmConf(array $emConf)
87  {
88  if (
89  !isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])
90  || !isset($emConf['constraints']['conflicts']) || !isset($emConf['constraints']['suggests'])
91  ) {
92  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])) {
93  $emConf['constraints']['depends'] = $this->stringToDependency($emConf['dependencies'] ?? '');
94  if (isset($emConf['PHP_version']) && (string)$emConf['PHP_version'] !== '') {
95  $emConf['constraints']['depends']['php'] = $emConf['PHP_version'];
96  }
97  if (isset($emConf['TYPO3_version']) && (string)$emConf['TYPO3_version'] !== '') {
98  $emConf['constraints']['depends']['typo3'] = $emConf['TYPO3_version'];
99  }
100  }
101  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['conflicts'])) {
102  $emConf['constraints']['conflicts'] = $this->stringToDependency($emConf['conflicts'] ?? '');
103  }
104  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['suggests'])) {
105  $emConf['constraints']['suggests'] = [];
106  }
107  }
108 
109  // Remove TER v1-style entries
110  unset($emConf['dependencies']);
111  unset($emConf['conflicts']);
112  unset($emConf['suggests']);
113  unset($emConf['private']);
114  unset($emConf['download_password']);
115  unset($emConf['TYPO3_version']);
116  unset($emConf['PHP_version']);
117  unset($emConf['internal']);
118  unset($emConf['module']);
119  unset($emConf['loadOrder']);
120  unset($emConf['lockType']);
121  unset($emConf['shy']);
122  unset($emConf['priority']);
123  unset($emConf['modify_tables']);
124  unset($emConf['CGLcompliance']);
125  unset($emConf['CGLcompliance_note']);
126 
127  return $emConf;
128  }
129 
141  public function stringToDependency($dependency)
142  {
143  $constraint = [];
144  if (is_string($dependency) && $dependency !== '') {
145  $dependency = explode(',', $dependency);
146  foreach ($dependency as $v) {
147  $constraint[$v] = '';
148  }
149  }
150  return $constraint;
151  }
152 }
‪TYPO3\CMS\Extensionmanager\Utility
‪TYPO3\CMS\Core\Core\Environment\getPublicPath
‪static string getPublicPath()
Definition: Environment.php:153
‪TYPO3
‪TYPO3\CMS\Core\SingletonInterface
Definition: SingletonInterface.php:22
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪$EM_CONF
‪$EM_CONF[$_EXTKEY]
Definition: ext_emconf.php:2