‪TYPO3CMS  ‪main
EmConfUtility.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 class EmConfUtility
25 {
33  public function includeEmConf(string $extensionKey, string $absolutePath): array|false
34  {
35  $_EXTKEY = $extensionKey;
36  $path = rtrim($absolutePath, '/') . '/ext_emconf.php';
37  ‪$EM_CONF = null;
38  if (!empty($absolutePath) && file_exists($path)) {
39  include $path;
40  if (is_array(‪$EM_CONF[$_EXTKEY])) {
41  return ‪$EM_CONF[$_EXTKEY];
42  }
43  }
44  return false;
45  }
46 
50  public function constructEmConf(string $extensionKey, array $emConf): string
51  {
52  $emConf = $this->fixEmConf($emConf);
53  $emConf = var_export($emConf, true);
54  return '<?php
55 
56 /***************************************************************
57  * Extension Manager/Repository config file for ext "' . $extensionKey . '".
58  *
59  * Auto generated ' . date('d-m-Y H:i') . '
60  *
61  * Manual updates:
62  * Only the data in the array - everything else is removed by next
63  * writing. "version" and "dependencies" must not be touched!
64  ***************************************************************/
65 
66 $EM_CONF[$_EXTKEY] = ' . $emConf . ';
67 
68 ';
69  }
70 
74  protected function fixEmConf(array $emConf): array
75  {
76  if (
77  !isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])
78  || !isset($emConf['constraints']['conflicts']) || !isset($emConf['constraints']['suggests'])
79  ) {
80  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])) {
81  $emConf['constraints']['depends'] = $this->stringToDependency($emConf['dependencies'] ?? '');
82  if (isset($emConf['PHP_version']) && (string)$emConf['PHP_version'] !== '') {
83  $emConf['constraints']['depends']['php'] = $emConf['PHP_version'];
84  }
85  if (isset($emConf['TYPO3_version']) && (string)$emConf['TYPO3_version'] !== '') {
86  $emConf['constraints']['depends']['typo3'] = $emConf['TYPO3_version'];
87  }
88  }
89  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['conflicts'])) {
90  $emConf['constraints']['conflicts'] = $this->stringToDependency($emConf['conflicts'] ?? '');
91  }
92  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['suggests'])) {
93  $emConf['constraints']['suggests'] = [];
94  }
95  }
96 
97  // Remove TER v1-style entries
98  unset($emConf['dependencies']);
99  unset($emConf['conflicts']);
100  unset($emConf['suggests']);
101  unset($emConf['private']);
102  unset($emConf['download_password']);
103  unset($emConf['TYPO3_version']);
104  unset($emConf['PHP_version']);
105  unset($emConf['internal']);
106  unset($emConf['module']);
107  unset($emConf['loadOrder']);
108  unset($emConf['lockType']);
109  unset($emConf['createDirs']);
110  unset($emConf['shy']);
111  unset($emConf['priority']);
112  unset($emConf['modify_tables']);
113  unset($emConf['CGLcompliance']);
114  unset($emConf['CGLcompliance_note']);
115 
116  return $emConf;
117  }
118 
130  protected function stringToDependency(string|array $dependency): array
131  {
132  $constraint = [];
133  if (is_string($dependency) && $dependency !== '') {
134  $dependency = explode(',', $dependency);
135  foreach ($dependency as $v) {
136  $constraint[$v] = '';
137  }
138  }
139  return $constraint;
140  }
141 }
‪TYPO3\CMS\Extensionmanager\Utility
Definition: DependencyUtility.php:18
‪$EM_CONF
‪$EM_CONF[$_EXTKEY]
Definition: ext_emconf.php:3