TYPO3 CMS  TYPO3_8-7
LoadedExtensionsArray.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 
22 class LoadedExtensionsArray implements \Iterator, \ArrayAccess, \Serializable, \Countable
23 {
27  protected $packageManager;
28 
33 
37  protected $iteratorPosition;
38 
42  public function __construct(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
43  {
44  $this->packageManager = $packageManager;
45  }
46 
54  public function offsetExists($offset)
55  {
56  return $this->packageManager->isPackageActive($offset);
57  }
58 
66  public function offsetGet($offset)
67  {
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);
73  }
74  return $this->loadedExtensionArrayElementCache[$packageKey];
75  }
76 
85  public function offsetSet($offset, $value)
86  {
87  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915596);
88  }
89 
97  public function offsetUnset($offset)
98  {
99  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915610);
100  }
101 
108  public function serialize()
109  {
110  return serialize($this->loadedExtensionArrayElementCache);
111  }
112 
120  public function unserialize($serialized)
121  {
122  $this->loadedExtensionArrayElementCache = unserialize($serialized);
123  }
124 
131  public function count()
132  {
133  return count($this->packageManager->getActivePackages());
134  }
135 
142  public function current()
143  {
144  return $this->offsetGet($this->iteratorPosition);
145  }
146 
152  public function next()
153  {
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];
158  } else {
159  $this->iteratorPosition = null;
160  }
161  }
162 
169  public function key()
170  {
172  }
173 
180  public function valid()
181  {
182  return $this->offsetExists($this->iteratorPosition);
183  }
184 
190  public function rewind()
191  {
192  $keys = array_keys($this->packageManager->getActivePackages());
193  $this->iteratorPosition = array_shift($keys);
194  }
195 
199  public function reset()
200  {
201  $this->loadedExtensionArrayElementCache = [];
202  $this->rewind();
203  }
204 
210  public function hasPackageManager()
211  {
212  return $this->packageManager !== null;
213  }
214 
218  public function toArray()
219  {
220  return array_map(
221  function ($loadedExtElement) {
222  return $loadedExtElement->toArray();
223  },
224  iterator_to_array($this)
225  );
226  }
227 }
__construct(\TYPO3\CMS\Core\Package\PackageManager $packageManager)