TYPO3 CMS  TYPO3_7-6
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 
21 {
28  public function includeEmConf(array $extension)
29  {
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 
51  public function constructEmConf(array $extensionData, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension = null)
52  {
53  if (is_object($extension) && empty($extensionData['EM_CONF']['constraints'])) {
54  $extensionData['EM_CONF']['constraints'] = unserialize($extension->getSerializedDependencies());
55  }
56  $emConf = $this->fixEmConf($extensionData['EM_CONF']);
57  $emConf = var_export($emConf, true);
58  $code = '<?php
59 
60 /***************************************************************
61  * Extension Manager/Repository config file for ext "' . $extensionData['extKey'] . '".
62  *
63  * Auto generated ' . date('d-m-Y H:i') . '
64  *
65  * Manual updates:
66  * Only the data in the array - everything else is removed by next
67  * writing. "version" and "dependencies" must not be touched!
68  ***************************************************************/
69 
70 $EM_CONF[$_EXTKEY] = ' . $emConf . ';
71 
72 ';
73  return $code;
74  }
75 
82  public function fixEmConf(array $emConf)
83  {
84  if (
85  !isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])
86  || !isset($emConf['constraints']['conflicts']) || !isset($emConf['constraints']['suggests'])
87  ) {
88  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['depends'])) {
89  $emConf['constraints']['depends'] = $this->stringToDependency($emConf['dependencies']);
90  if ((string)$emConf['PHP_version'] !== '') {
91  $emConf['constraints']['depends']['php'] = $emConf['PHP_version'];
92  }
93  if ((string)$emConf['TYPO3_version'] !== '') {
94  $emConf['constraints']['depends']['typo3'] = $emConf['TYPO3_version'];
95  }
96  }
97  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['conflicts'])) {
98  $emConf['constraints']['conflicts'] = $this->stringToDependency($emConf['conflicts']);
99  }
100  if (!isset($emConf['constraints']) || !isset($emConf['constraints']['suggests'])) {
101  $emConf['constraints']['suggests'] = [];
102  }
103  }
104 
105  // Remove TER v1-style entries
106  unset($emConf['dependencies']);
107  unset($emConf['conflicts']);
108  unset($emConf['suggests']);
109  unset($emConf['private']);
110  unset($emConf['download_password']);
111  unset($emConf['TYPO3_version']);
112  unset($emConf['PHP_version']);
113  unset($emConf['internal']);
114  unset($emConf['module']);
115  unset($emConf['loadOrder']);
116  unset($emConf['lockType']);
117  unset($emConf['shy']);
118  unset($emConf['priority']);
119  unset($emConf['modify_tables']);
120  unset($emConf['CGLcompliance']);
121  unset($emConf['CGLcompliance_note']);
122 
123  return $emConf;
124  }
125 
137  public function stringToDependency($dependency)
138  {
139  $constraint = [];
140  if (is_string($dependency) && $dependency !== '') {
141  $dependency = explode(',', $dependency);
142  foreach ($dependency as $v) {
143  $constraint[$v] = '';
144  }
145  }
146  return $constraint;
147  }
148 }
constructEmConf(array $extensionData, \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension=null)
$EM_CONF[$_EXTKEY]
Definition: ext_emconf.php:2