TYPO3 CMS  TYPO3_7-6
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 
86  public function offsetSet($offset, $value)
87  {
88  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915596);
89  }
90 
99  public function offsetUnset($offset)
100  {
101  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915610);
102  }
103 
110  public function serialize()
111  {
112  return serialize($this->loadedExtensionArrayElementCache);
113  }
114 
122  public function unserialize($serialized)
123  {
124  $this->loadedExtensionArrayElementCache = unserialize($serialized);
125  }
126 
133  public function count()
134  {
135  return count($this->packageManager->getActivePackages());
136  }
137 
144  public function current()
145  {
146  return $this->offsetGet($this->iteratorPosition);
147  }
148 
155  public function next()
156  {
157  $packageKeys = array_keys($this->packageManager->getActivePackages());
158  $position = array_search($this->iteratorPosition, $packageKeys);
159  if (isset($packageKeys[$position + 1])) {
160  $this->iteratorPosition = $packageKeys[$position + 1];
161  } else {
162  $this->iteratorPosition = null;
163  }
164  }
165 
172  public function key()
173  {
175  }
176 
183  public function valid()
184  {
185  return $this->offsetExists($this->iteratorPosition);
186  }
187 
194  public function rewind()
195  {
196  $keys = array_keys($this->packageManager->getActivePackages());
197  $this->iteratorPosition = array_shift($keys);
198  }
199 
205  public function reset()
206  {
207  $this->loadedExtensionArrayElementCache = [];
208  $this->rewind();
209  }
210 
216  public function hasPackageManager()
217  {
218  return $this->packageManager !== null;
219  }
220 
224  public function toArray()
225  {
226  return array_map(
227  function ($loadedExtElement) {
228  return $loadedExtElement->toArray();
229  },
230  iterator_to_array($this)
231  );
232  }
233 }
__construct(\TYPO3\CMS\Core\Package\PackageManager $packageManager)