TYPO3 CMS  TYPO3_6-2
LoadedExtensionsArray.php
Go to the documentation of this file.
1 <?php
21 class LoadedExtensionsArray implements \Iterator, \ArrayAccess, \Serializable, \Countable {
22 
26  protected $packageManager;
27 
31  protected $loadedExtensionArrayElementCache = array();
32 
36  protected $iteratorPosition;
37 
41  public function __construct(\TYPO3\CMS\Core\Package\PackageManager $packageManager) {
42  $this->packageManager = $packageManager;
43  }
44 
52  public function offsetExists($offset) {
53  return $this->packageManager->isPackageActive($offset);
54  }
55 
63  public function offsetGet($offset) {
64  // Pass it through the package manager, as it resolves package aliases
65  $package = $this->packageManager->getPackage($offset);
66  $packageKey = $package->getPackageKey();
67  if (!isset($this->loadedExtensionArrayElementCache[$packageKey])) {
68  $this->loadedExtensionArrayElementCache[$packageKey] = new LoadedExtensionArrayElement($package);
69  }
70  return $this->loadedExtensionArrayElementCache[$packageKey];
71  }
72 
82  public function offsetSet($offset, $value) {
83  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915596);
84  }
85 
94  public function offsetUnset($offset) {
95  throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915610);
96  }
97 
104  public function serialize() {
105  return serialize($this->loadedExtensionArrayElementCache);
106  }
107 
115  public function unserialize($serialized) {
116  $this->loadedExtensionArrayElementCache = unserialize($serialized);
117  }
118 
125  public function count() {
126  return count($this->packageManager->getActivePackages());
127  }
128 
129 
136  public function current() {
137  return $this->offsetGet($this->iteratorPosition);
138  }
139 
146  public function next() {
147  $packageKeys = array_keys($this->packageManager->getActivePackages());
148  $position = array_search($this->iteratorPosition, $packageKeys);
149  if (isset($packageKeys[$position + 1])) {
150  $this->iteratorPosition = $packageKeys[$position + 1];
151  } else {
152  $this->iteratorPosition = NULL;
153  }
154  }
155 
162  public function key() {
164  }
165 
172  public function valid() {
173  return $this->offsetExists($this->iteratorPosition);
174  }
175 
182  public function rewind() {
183  $keys = array_keys($this->packageManager->getActivePackages());
184  $this->iteratorPosition = array_shift($keys);
185  }
186 
192  public function reset() {
193  $this->loadedExtensionArrayElementCache = array();
194  $this->rewind();
195  }
196 
202  public function hasPackageManager() {
203  return $this->packageManager !== NULL;
204  }
205 
209  public function toArray() {
210  return array_map(
211  function($loadedExtElement) {
212  return $loadedExtElement->toArray();
213  },
214  iterator_to_array($this)
215  );
216  }
217 }
__construct(\TYPO3\CMS\Core\Package\PackageManager $packageManager)