TYPO3  7.6
LoadedExtensionsArray.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Compatibility;
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 
32  protected $loadedExtensionArrayElementCache = array();
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 
138 
145  public function current()
146  {
147  return $this->offsetGet($this->iteratorPosition);
148  }
149 
156  public function next()
157  {
158  $packageKeys = array_keys($this->packageManager->getActivePackages());
159  $position = array_search($this->iteratorPosition, $packageKeys);
160  if (isset($packageKeys[$position + 1])) {
161  $this->iteratorPosition = $packageKeys[$position + 1];
162  } else {
163  $this->iteratorPosition = null;
164  }
165  }
166 
173  public function key()
174  {
176  }
177 
184  public function valid()
185  {
186  return $this->offsetExists($this->iteratorPosition);
187  }
188 
195  public function rewind()
196  {
197  $keys = array_keys($this->packageManager->getActivePackages());
198  $this->iteratorPosition = array_shift($keys);
199  }
200 
206  public function reset()
207  {
208  $this->loadedExtensionArrayElementCache = array();
209  $this->rewind();
210  }
211 
217  public function hasPackageManager()
218  {
219  return $this->packageManager !== null;
220  }
221 
225  public function toArray()
226  {
227  return array_map(
228  function ($loadedExtElement) {
229  return $loadedExtElement->toArray();
230  },
231  iterator_to_array($this)
232  );
233  }
234 }