[TASK] Remove unused EM_CONF variables
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / EmConfUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
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 /**
17 * Utility for dealing with ext_emconf
18 *
19 * @author Susanne Moog <susanne.moog@typo3.org>
20 */
21 class EmConfUtility implements \TYPO3\CMS\Core\SingletonInterface {
22
23 /**
24 * Returns the $EM_CONF array from an extensions ext_emconf.php file
25 *
26 * @param array $extension Extension information array
27 * @return array EMconf array values.
28 */
29 public function includeEmConf(array $extension) {
30 $_EXTKEY = $extension['key'];
31 $path = PATH_site . $extension['siteRelPath'] . 'ext_emconf.php';
32 $EM_CONF = NULL;
33 if (file_exists($path)) {
34 include $path;
35 if (is_array($EM_CONF[$_EXTKEY])) {
36 return $EM_CONF[$_EXTKEY];
37 }
38 }
39 return FALSE;
40 }
41
42 /**
43 * Generates the content for the ext_emconf.php file
44 * Sets dependencies from TER data if any
45 *
46 * @internal
47 * @param array $extensionData
48 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension Extension object from TER data
49 * @return string
50 */
51 public function constructEmConf(array $extensionData, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension = NULL) {
52 if (is_object($extension)) {
53 $extensionData['EM_CONF']['constraints'] = unserialize($extension->getSerializedDependencies());
54 }
55 $emConf = $this->fixEmConf($extensionData['EM_CONF']);
56 $emConf = var_export($emConf, TRUE);
57 $code = '<?php
58
59 /***************************************************************
60 * Extension Manager/Repository config file for ext "' . $extensionData['extKey'] . '".
61 *
62 * Auto generated ' . date('d-m-Y H:i') . '
63 *
64 * Manual updates:
65 * Only the data in the array - everything else is removed by next
66 * writing. "version" and "dependencies" must not be touched!
67 ***************************************************************/
68
69 $EM_CONF[$_EXTKEY] = ' . $emConf . ';
70
71 ';
72 return str_replace(' ', TAB, $code);
73 }
74
75 /**
76 * Fix the em conf - Converts old / ter em_conf format to new format
77 *
78 * @param array $emConf
79 * @return array
80 */
81 public function fixEmConf(array $emConf) {
82 if (
83 !isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])
84 || !isset($emConf['constraints']['conflicts']) || !isset($emConf['constraints']['suggests'])
85 ) {
86 if (!isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])) {
87 $emConf['constraints']['depends'] = $this->stringToDependency($emConf['dependencies']);
88 if (strlen($emConf['PHP_version'])) {
89 $emConf['constraints']['depends']['php'] = $emConf['PHP_version'];
90 }
91 if (strlen($emConf['TYPO3_version'])) {
92 $emConf['constraints']['depends']['typo3'] = $emConf['TYPO3_version'];
93 }
94 }
95 if (!isset($emConf['constraints']) || !isset($emConf['constraints']['conflicts'])) {
96 $emConf['constraints']['conflicts'] = $this->stringToDependency($emConf['conflicts']);
97 }
98 if (!isset($emConf['constraints']) || !isset($emConf['constraints']['suggests'])) {
99 $emConf['constraints']['suggests'] = array();
100 }
101 }
102
103 // Remove TER v1-style entries
104 unset($emConf['dependencies']);
105 unset($emConf['conflicts']);
106 unset($emConf['suggests']);
107 unset($emConf['private']);
108 unset($emConf['download_password']);
109 unset($emConf['TYPO3_version']);
110 unset($emConf['PHP_version']);
111 unset($emConf['internal']);
112 unset($emConf['module']);
113 unset($emConf['loadOrder']);
114 unset($emConf['lockType']);
115 unset($emConf['shy']);
116 unset($emConf['priority']);
117 unset($emConf['modify_tables']);
118 unset($emConf['CGLcompliance']);
119 unset($emConf['CGLcompliance_note']);
120
121 return $emConf;
122 }
123
124 /**
125 * Checks whether the passed dependency is TER-style (string) or
126 * TER2-style (array) and returns a single string for displaying the
127 * dependencies.
128 *
129 * It leaves out all version numbers and the "php" and "typo3" dependencies,
130 * as they are implicit and of no interest without the version number.
131 *
132 * @param mixed $dependency Either a string or an array listing dependencies.
133 * @return string A simple dependency list for display
134 */
135 public function stringToDependency($dependency) {
136 $constraint = array();
137 if (is_string($dependency) && strlen($dependency)) {
138 $dependency = explode(',', $dependency);
139 foreach ($dependency as $v) {
140 $constraint[$v] = '';
141 }
142 }
143 return $constraint;
144 }
145
146 }