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\Package\PackageInterface
;
20 * Class to simulate the "old" extension information array element
24 class LoadedExtensionArrayElement
implements \IteratorAggregate
, \ArrayAccess
, \Serializable
, \Countable
27 * @var PackageInterface Instance of package manager
32 * @var array List of relevant extension files
34 protected $extensionFilesToCheckFor = array(
38 'ext_tables_static+adt.sql',
39 'ext_typoscript_constants.txt',
40 'ext_typoscript_setup.txt'
44 * @var array Final extension information
46 protected $extensionInformation = array();
49 * Constructor builds compatibility API
51 * @param PackageInterface $package
53 public function __construct(PackageInterface
$package)
55 $this->package
= $package;
56 $this->initializeBasicExtensionInformation();
57 $this->initializeExtensionFiles();
58 $this->initializeExtensionIcon();
62 * Create main information
66 protected function initializeBasicExtensionInformation()
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;
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':
80 $relativePackagePathToPathTypo3 = '../typo3conf/Packages/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
84 $relativePackagePathToPathTypo3 = '../typo3conf/ext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
86 case TYPO3_mainDir
. 'ext':
88 $relativePackagePathToPathTypo3 = 'ext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
90 case TYPO3_mainDir
. 'sysext':
92 $relativePackagePathToPathTypo3 = 'sysext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
94 case 'typo3temp/var/tests/test_ext':
96 $relativePackagePathToPathTypo3 = '../typo3temp/var/tests/test_ext/' . implode('/', array_slice($relativePackagePathToPathSiteSegments, 2));
99 if ($packageType !== null && $relativePackagePathToPathSite !== null && $relativePackagePathToPathTypo3 !== null) {
100 $this->extensionInformation
['type'] = $packageType;
101 $this->extensionInformation
['siteRelPath'] = $relativePackagePathToPathSite;
102 $this->extensionInformation
['typo3RelPath'] = $relativePackagePathToPathTypo3;
108 * Initialize extension icon
112 protected function initializeExtensionIcon()
114 $this->extensionInformation
['ext_icon'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility
::getExtensionIcon($this->package
->getPackagePath());
118 * Register found files in extension array if extension was found
122 protected function initializeExtensionFiles()
124 foreach ($this->extensionFilesToCheckFor
as $fileName) {
125 $absolutePathToFile = $this->package
->getPackagePath() . $fileName;
126 if (@file_exists
($absolutePathToFile)) {
127 $this->extensionInformation
[$fileName] = $absolutePathToFile;
133 * Retrieve an external iterator
135 * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
136 * @return \Traversable An instance of an object implementing Iterator or Traversable
138 public function getIterator()
140 return new \
ArrayIterator($this->extensionInformation
);
144 * Whether an offset exists
146 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
147 * @param mixed $offset An offset to check for.
148 * @return bool TRUE on success or FALSE on failure.
150 public function offsetExists($offset)
152 return isset($this->extensionInformation
[$offset]);
158 * @link http://php.net/manual/en/arrayaccess.offsetget.php
159 * @param mixed $offset The offset to retrieve.
160 * @return mixed Can return all value types.
162 public function offsetGet($offset)
164 return $this->extensionInformation
[$offset];
170 * @link http://php.net/manual/en/arrayaccess.offsetset.php
171 * @param mixed $offset The offset to assign the value to.
172 * @param mixed $value The value to set.
174 * @throws \InvalidArgumentException
176 public function offsetSet($offset, $value)
178 throw new \
InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915115);
184 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
185 * @param mixed $offset The offset to unset.
187 * @throws \InvalidArgumentException
189 public function offsetUnset($offset)
191 throw new \
InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915206);
195 * String representation of object
197 * @link http://php.net/manual/en/serializable.serialize.php
198 * @return string the string representation of the object or null
200 public function serialize()
202 return serialize($this->extensionInformation
);
206 * Constructs the object
208 * @link http://php.net/manual/en/serializable.unserialize.php
209 * @param string $serialized The string representation of the object.
210 * @return mixed the original value unserialized.
212 public function unserialize($serialized)
214 $this->extensionInformation
= unserialize($serialized);
218 * Count elements of an object
220 * @link http://php.net/manual/en/countable.count.php
221 * @return int The custom count as an integer. The return value is cast to an integer.
223 public function count()
225 return count($this->extensionInformation
);
231 public function toArray()
233 return iterator_to_array($this);