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!
18 * Class to simulate the "old" extension information array
22 class LoadedExtensionsArray
implements \Iterator
, \ArrayAccess
, \Serializable
, \Countable
25 * @var \TYPO3\CMS\Core\Package\PackageManager Instance of package manager
27 protected $packageManager;
30 * @var array Loaded element cache
32 protected $loadedExtensionArrayElementCache = [];
35 * @var string Pointer to current position
37 protected $iteratorPosition;
40 * @param \TYPO3\CMS\Core\Package\PackageManager $packageManager
42 public function __construct(\TYPO3\CMS\Core\Package\PackageManager
$packageManager)
44 $this->packageManager
= $packageManager;
48 * Whether an offset exists
50 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
51 * @param mixed $offset An offset to check for.
52 * @return bool TRUE on success or FALSE on failure.
54 public function offsetExists($offset)
56 return $this->packageManager
->isPackageActive($offset);
62 * @link http://php.net/manual/en/arrayaccess.offsetget.php
63 * @param mixed $offset The offset to retrieve.
64 * @return mixed Can return all value types.
66 public function offsetGet($offset)
68 // Pass it through the package manager, as it resolves package aliases
69 $package = $this->packageManager
->getPackage($offset);
70 $packageKey = $package->getPackageKey();
71 if (!isset($this->loadedExtensionArrayElementCache
[$packageKey])) {
72 $this->loadedExtensionArrayElementCache
[$packageKey] = new LoadedExtensionArrayElement($package);
74 return $this->loadedExtensionArrayElementCache
[$packageKey];
80 * @link http://php.net/manual/en/arrayaccess.offsetset.php
81 * @param mixed $offset The offset to assign the value to.
82 * @param mixed $value The value to set.
83 * @throws \InvalidArgumentException
85 public function offsetSet($offset, $value)
87 throw new \
InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915596);
93 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
94 * @param mixed $offset The offset to unset.
95 * @throws \InvalidArgumentException
97 public function offsetUnset($offset)
99 throw new \
InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915610);
103 * String representation of object
105 * @link http://php.net/manual/en/serializable.serialize.php
106 * @return string the string representation of the object or null
108 public function serialize()
110 return serialize($this->loadedExtensionArrayElementCache
);
114 * Constructs the object
116 * @link http://php.net/manual/en/serializable.unserialize.php
117 * @param string $serialized The string representation of the object.
118 * @return mixed the original value unserialized.
120 public function unserialize($serialized)
122 $this->loadedExtensionArrayElementCache
= unserialize($serialized);
126 * Count elements of an object
128 * @link http://php.net/manual/en/countable.count.php
129 * @return int The custom count as an integer.
131 public function count()
133 return count($this->packageManager
->getActivePackages());
137 * Return the current element
139 * @link http://php.net/manual/en/iterator.current.php
140 * @return mixed Can return any type.
142 public function current()
144 return $this->offsetGet($this->iteratorPosition
);
148 * Move forward to next element
150 * @link http://php.net/manual/en/iterator.next.php
152 public function next()
154 $packageKeys = array_keys($this->packageManager
->getActivePackages());
155 $position = array_search($this->iteratorPosition
, $packageKeys);
156 if (isset($packageKeys[$position +
1])) {
157 $this->iteratorPosition
= $packageKeys[$position +
1];
159 $this->iteratorPosition
= null;
164 * Return the key of the current element
166 * @link http://php.net/manual/en/iterator.key.php
167 * @return mixed scalar on success, or null on failure.
169 public function key()
171 return $this->iteratorPosition
;
175 * Checks if current position is valid
177 * @link http://php.net/manual/en/iterator.valid.php
178 * @return bool The return value will be casted to boolean and then evaluated. Returns true on success or false on failure.
180 public function valid()
182 return $this->offsetExists($this->iteratorPosition
);
186 * Rewind the Iterator to the first element
188 * @link http://php.net/manual/en/iterator.rewind.php
190 public function rewind()
192 $keys = array_keys($this->packageManager
->getActivePackages());
193 $this->iteratorPosition
= array_shift($keys);
199 public function reset()
201 $this->loadedExtensionArrayElementCache
= [];
206 * Whether package manager is set in class
208 * @return bool TRUE if package manager is set
210 public function hasPackageManager()
212 return $this->packageManager
!== null;
218 public function toArray()
221 function ($loadedExtElement) {
222 return $loadedExtElement->toArray();
224 iterator_to_array($this)