TYPO3 CMS  TYPO3_8-7
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.typoscript',
40  'ext_typoscript_setup.typoscript',
41  'ext_typoscript_constants.txt',
42  'ext_typoscript_setup.txt'
43  ];
44 
48  protected $extensionInformation = [];
49 
56  {
57  $this->package = $package;
59  $this->initializeExtensionFiles();
60  $this->initializeExtensionIcon();
61  }
62 
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  $packageType = null;
75  // Determine if extension is installed locally, globally or system (in this order)
76  switch (implode('/', array_slice($relativePackagePathToPathSiteSegments, 0, 2))) {
77  case 'typo3conf/ext':
78  $packageType = 'L';
79  break;
80  case TYPO3_mainDir . 'ext':
81  $packageType = 'G';
82  break;
83  case TYPO3_mainDir . 'sysext':
84  $packageType = 'S';
85  break;
86  case 'typo3temp/var/tests/test_ext':
87  $packageType = 'T';
88  break;
89  }
90  if ($packageType !== null) {
91  $this->extensionInformation['type'] = $packageType;
92  }
93  }
94  }
95 
99  protected function initializeExtensionIcon()
100  {
101  $this->extensionInformation['ext_icon'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($this->package->getPackagePath());
102  }
103 
107  protected function initializeExtensionFiles()
108  {
109  foreach ($this->extensionFilesToCheckFor as $fileName) {
110  $absolutePathToFile = $this->package->getPackagePath() . $fileName;
111  if (@file_exists($absolutePathToFile)) {
112  $this->extensionInformation[$fileName] = $absolutePathToFile;
113  }
114  }
115  }
116 
123  public function getIterator()
124  {
125  return new \ArrayIterator($this->extensionInformation);
126  }
127 
135  public function offsetExists($offset)
136  {
137  return isset($this->extensionInformation[$offset]);
138  }
139 
147  public function offsetGet($offset)
148  {
149  return $this->extensionInformation[$offset];
150  }
151 
160  public function offsetSet($offset, $value)
161  {
162  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915115);
163  }
164 
172  public function offsetUnset($offset)
173  {
174  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915206);
175  }
176 
183  public function serialize()
184  {
185  return serialize($this->extensionInformation);
186  }
187 
195  public function unserialize($serialized)
196  {
197  $this->extensionInformation = unserialize($serialized);
198  }
199 
206  public function count()
207  {
208  return count($this->extensionInformation);
209  }
210 
214  public function toArray()
215  {
216  return iterator_to_array($this);
217  }
218 }
static getExtensionIcon($extensionPath, $returnFullPath=false)