2 namespace TYPO3\CMS\Core\Compatibility
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Core\Environment
;
18 use TYPO3\CMS\Core\Package\PackageInterface
;
21 * Class to simulate the "old" extension information array element
25 class LoadedExtensionArrayElement
implements \IteratorAggregate
, \ArrayAccess
, \Serializable
, \Countable
28 * @var PackageInterface Instance of package manager
33 * @var array List of relevant extension files
35 protected $extensionFilesToCheckFor = [
39 'ext_tables_static+adt.sql',
40 'ext_typoscript_constants.typoscript',
41 'ext_typoscript_setup.typoscript',
42 'ext_typoscript_constants.txt',
43 'ext_typoscript_setup.txt'
47 * @var array Final extension information
49 protected $extensionInformation = [];
52 * Constructor builds compatibility API
54 * @param PackageInterface $package
56 public function __construct(PackageInterface
$package)
58 $this->package
= $package;
59 $this->initializeBasicExtensionInformation();
60 $this->initializeExtensionFiles();
61 $this->initializeExtensionIcon();
65 * Create main information
67 protected function initializeBasicExtensionInformation()
69 $pathSite = Environment
::getPublicPath() . '/';
70 $pathSiteLength = strlen($pathSite);
71 $absolutePackagePath = $this->package
->getPackagePath();
72 if (strpos($absolutePackagePath, $pathSite) === 0) {
73 $relativePackagePathToPathSite = substr($absolutePackagePath, $pathSiteLength);
74 $relativePackagePathToPathSiteSegments = explode('/', $relativePackagePathToPathSite);
76 // Determine if extension is installed locally, globally or system (in this order)
77 switch (implode('/', array_slice($relativePackagePathToPathSiteSegments, 0, 2))) {
81 case TYPO3_mainDir
. 'ext':
84 case TYPO3_mainDir
. 'sysext':
87 case 'typo3temp/var/tests/test_ext':
91 if ($packageType !== null) {
92 $this->extensionInformation
['type'] = $packageType;
98 * Initialize extension icon
100 protected function initializeExtensionIcon()
102 $this->extensionInformation
['ext_icon'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::getExtensionIcon($this->package
->getPackagePath());
106 * Register found files in extension array if extension was found
108 protected function initializeExtensionFiles()
110 foreach ($this->extensionFilesToCheckFor
as $fileName) {
111 $absolutePathToFile = $this->package
->getPackagePath() . $fileName;
112 if (@file_exists
($absolutePathToFile)) {
113 $this->extensionInformation
[$fileName] = $absolutePathToFile;
119 * Retrieve an external iterator
121 * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
122 * @return \Traversable An instance of an object implementing Iterator or Traversable
124 public function getIterator()
126 return new \
ArrayIterator($this->extensionInformation
);
130 * Whether an offset exists
132 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
133 * @param mixed $offset An offset to check for.
134 * @return bool TRUE on success or FALSE on failure.
136 public function offsetExists($offset)
138 return isset($this->extensionInformation
[$offset]);
144 * @link http://php.net/manual/en/arrayaccess.offsetget.php
145 * @param mixed $offset The offset to retrieve.
146 * @return mixed Can return all value types.
148 public function offsetGet($offset)
150 return $this->extensionInformation
[$offset];
156 * @link http://php.net/manual/en/arrayaccess.offsetset.php
157 * @param mixed $offset The offset to assign the value to.
158 * @param mixed $value The value to set.
159 * @throws \InvalidArgumentException
161 public function offsetSet($offset, $value)
163 throw new \
InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915115);
169 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
170 * @param mixed $offset The offset to unset.
171 * @throws \InvalidArgumentException
173 public function offsetUnset($offset)
175 throw new \
InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915206);
179 * String representation of object
181 * @link http://php.net/manual/en/serializable.serialize.php
182 * @return string the string representation of the object or null
184 public function serialize()
186 return serialize($this->extensionInformation
);
190 * Constructs the object
192 * @link http://php.net/manual/en/serializable.unserialize.php
193 * @param string $serialized The string representation of the object.
194 * @return mixed the original value unserialized.
196 public function unserialize($serialized)
198 $this->extensionInformation
= unserialize($serialized);
202 * Count elements of an object
204 * @link http://php.net/manual/en/countable.count.php
205 * @return int The custom count as an integer. The return value is cast to an integer.
207 public function count()
209 return count($this->extensionInformation
);
215 public function toArray()
217 return iterator_to_array($this);