TYPO3 CMS  TYPO3_7-6
LoadedExtensionArrayElement.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 
18 
24 class LoadedExtensionArrayElement implements \IteratorAggregate, \ArrayAccess, \Serializable, \Countable
25 {
29  protected $package;
30 
35  'ext_localconf.php',
36  'ext_tables.php',
37  'ext_tables.sql',
38  'ext_tables_static+adt.sql',
39  'ext_typoscript_constants.txt',
40  'ext_typoscript_setup.txt'
41  ];
42 
46  protected $extensionInformation = [];
47 
54  {
55  $this->package = $package;
57  $this->initializeExtensionFiles();
58  $this->initializeExtensionIcon();
59  }
60 
67  {
68  $pathSite = PATH_site;
69  $pathSiteLength = strlen($pathSite);
70  $absolutePackagePath = $this->package->getPackagePath();
71  if (substr($absolutePackagePath, 0, $pathSiteLength) === $pathSite) {
72  $relativePackagePathToPathSite = substr($absolutePackagePath, $pathSiteLength);
73  $relativePackagePathToPathSiteSegments = explode('/', $relativePackagePathToPathSite);
74  $relativePackagePathToPathTypo3 = null;
75  $packageType = null;
76  // Determine if extension is installed locally, globally or system (in this order)
77  switch (implode('/', array_slice($relativePackagePathToPathSiteSegments, 0, 2))) {
78  case 'typo3conf/Packages':
79  $packageType = 'C';
80  $relativePackagePathToPathTypo3 = '../typo3conf/Packages/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
81  break;
82  case 'typo3conf/ext':
83  $packageType = 'L';
84  $relativePackagePathToPathTypo3 = '../typo3conf/ext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
85  break;
86  case TYPO3_mainDir . 'ext':
87  $packageType = 'G';
88  $relativePackagePathToPathTypo3 = 'ext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
89  break;
90  case TYPO3_mainDir . 'sysext':
91  $packageType = 'S';
92  $relativePackagePathToPathTypo3 = 'sysext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
93  break;
94  case 'typo3temp/test_ext':
95  $packageType = 'T';
96  $relativePackagePathToPathTypo3 = '../typo3temp/test_ext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
97  break;
98  }
99  if ($packageType !== null && $relativePackagePathToPathSite !== null && $relativePackagePathToPathTypo3 !== null) {
100  $this->extensionInformation['type'] = $packageType;
101  $this->extensionInformation['siteRelPath'] = $relativePackagePathToPathSite;
102  $this->extensionInformation['typo3RelPath'] = $relativePackagePathToPathTypo3;
103  }
104  }
105  }
106 
112  protected function initializeExtensionIcon()
113  {
114  $this->extensionInformation['ext_icon'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($this->package->getPackagePath());
115  }
116 
122  protected function initializeExtensionFiles()
123  {
124  foreach ($this->extensionFilesToCheckFor as $fileName) {
125  $absolutePathToFile = $this->package->getPackagePath() . $fileName;
126  if (@file_exists($absolutePathToFile)) {
127  $this->extensionInformation[$fileName] = $absolutePathToFile;
128  }
129  }
130  }
131 
138  public function getIterator()
139  {
140  return new \ArrayIterator($this->extensionInformation);
141  }
142 
150  public function offsetExists($offset)
151  {
152  return isset($this->extensionInformation[$offset]);
153  }
154 
162  public function offsetGet($offset)
163  {
164  return $this->extensionInformation[$offset];
165  }
166 
176  public function offsetSet($offset, $value)
177  {
178  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915115);
179  }
180 
189  public function offsetUnset($offset)
190  {
191  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915206);
192  }
193 
200  public function serialize()
201  {
202  return serialize($this->extensionInformation);
203  }
204 
212  public function unserialize($serialized)
213  {
214  $this->extensionInformation = unserialize($serialized);
215  }
216 
223  public function count()
224  {
225  return count($this->extensionInformation);
226  }
227 
231  public function toArray()
232  {
233  return iterator_to_array($this);
234  }
235 }
static getExtensionIcon($extensionPath, $returnFullPath=false)