[TASK] Fix inline comment style for ext_emconf.php files
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Utility / EmConfUtility.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Susanne Moog <susanne.moog@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Utility for dealing with ext_emconf
31 *
32 * @author Susanne Moog <susanne.moog@typo3.org>
33 * @package Extension Manager
34 * @subpackage Utility
35 */
36 class EmConfUtility implements \TYPO3\CMS\Core\SingletonInterface {
37
38 /**
39 * Returns the $EM_CONF array from an extensions ext_emconf.php file
40 *
41 * @param array $extension Extension information array
42 * @return array EMconf array values.
43 */
44 public function includeEmConf(array $extension) {
45 $_EXTKEY = $extension['key'];
46 $path = PATH_site . $extension['siteRelPath'] . '/ext_emconf.php';
47 $EM_CONF = NULL;
48 if (file_exists($path)) {
49 include $path;
50 if (is_array($EM_CONF[$_EXTKEY])) {
51 return $EM_CONF[$_EXTKEY];
52 }
53 }
54 return FALSE;
55 }
56
57 /**
58 * Generates the content for the ext_emconf.php file
59 * Sets dependencies from TER data if any
60 *
61 * @internal
62 * @param array $extensionData
63 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension Extension object from TER data
64 * @return string
65 */
66 public function constructEmConf(array $extensionData, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension = NULL) {
67 if (is_object($extension)) {
68 $extensionData['EM_CONF']['constraints'] = unserialize($extension->getSerializedDependencies());
69 }
70 $emConf = $this->fixEmConf($extensionData['EM_CONF']);
71 $emConf = var_export($emConf, TRUE);
72 $code = '<?php
73
74 /***************************************************************
75 * Extension Manager/Repository config file for ext "' . $extensionData['extKey'] . '".
76 *
77 * Auto generated ' . date('d-m-Y H:i') . '
78 *
79 * Manual updates:
80 * Only the data in the array - everything else is removed by next
81 * writing. "version" and "dependencies" must not be touched!
82 ***************************************************************/
83
84 $EM_CONF[$_EXTKEY] = ' . $emConf . ';
85
86 ?>';
87 return str_replace(' ', TAB, $code);
88 }
89
90 /**
91 * Fix the em conf - Converts old / ter em_conf format to new format
92 *
93 * @param array $emConf
94 * @return array
95 */
96 public function fixEmConf(array $emConf) {
97 if (!isset($emConf['constraints']) || !isset($emConf['constraints']['depends']) || !isset($emConf['constraints']['conflicts']) || !isset($emConf['constraints']['suggests'])) {
98 if (!isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])) {
99 $emConf['constraints']['depends'] = $this->stringToDependency($emConf['dependencies']);
100 if (strlen($emConf['PHP_version'])) {
101 $emConf['constraints']['depends']['php'] = $emConf['PHP_version'];
102 }
103 if (strlen($emConf['TYPO3_version'])) {
104 $emConf['constraints']['depends']['typo3'] = $emConf['TYPO3_version'];
105 }
106 }
107 if (!isset($emConf['constraints']) || !isset($emConf['constraints']['conflicts'])) {
108 $emConf['constraints']['conflicts'] = $this->dependencyToString($emConf['conflicts']);
109 }
110 if (!isset($emConf['constraints']) || !isset($emConf['constraints']['suggests'])) {
111 $emConf['constraints']['suggests'] = array();
112 }
113 } elseif (isset($emConf['constraints']) && isset($emConf['dependencies'])) {
114 $emConf['suggests'] = isset($emConf['suggests']) ? $emConf['suggests'] : array();
115 $emConf['dependencies'] = $this->dependencyToString($emConf['constraints']);
116 $emConf['conflicts'] = $this->dependencyToString($emConf['constraints'], 'conflicts');
117 }
118 unset($emConf['private']);
119 unset($emConf['download_password']);
120 unset($emConf['TYPO3_version']);
121 unset($emConf['PHP_version']);
122 return $emConf;
123 }
124
125 /**
126 * Checks whether the passed dependency is TER2-style (array) and returns a
127 * single string for displaying the 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 * @param string $type The dependency type to list if $dep is an array
134 * @return string A simple dependency list for display
135 */
136 static public function dependencyToString($dependency, $type = 'depends') {
137 if (is_array($dependency)) {
138 if (isset($dependency[$type]['php'])) {
139 unset($dependency[$type]['php']);
140 }
141 if (isset($dependency[$type]['typo3'])) {
142 unset($dependency[$type]['typo3']);
143 }
144 $dependencyString = count($dependency[$type]) ? implode(',', array_keys($dependency[$type])) : '';
145 return $dependencyString;
146 }
147 return '';
148 }
149
150 /**
151 * Checks whether the passed dependency is TER-style (string) or
152 * TER2-style (array) and returns a single string for displaying the
153 * dependencies.
154 *
155 * It leaves out all version numbers and the "php" and "typo3" dependencies,
156 * as they are implicit and of no interest without the version number.
157 *
158 * @param mixed $dependency Either a string or an array listing dependencies.
159 * @return string A simple dependency list for display
160 */
161 public function stringToDependency($dependency) {
162 $constraint = array();
163 if (is_string($dependency) && strlen($dependency)) {
164 $dependency = explode(',', $dependency);
165 foreach ($dependency as $v) {
166 $constraint[$v] = '';
167 }
168 }
169 return $constraint;
170 }
171
172 }
173
174
175 ?>