‪TYPO3CMS  9.5
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 }
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray
Definition: LoadedExtensionsArray.php:23
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\unserialize
‪mixed unserialize($serialized)
Definition: LoadedExtensionsArray.php:117
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionArrayElement
Definition: LoadedExtensionArrayElement.php:26
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\reset
‪reset()
Definition: LoadedExtensionsArray.php:196
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\hasPackageManager
‪bool hasPackageManager()
Definition: LoadedExtensionsArray.php:207
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\offsetGet
‪mixed offsetGet($offset)
Definition: LoadedExtensionsArray.php:63
‪TYPO3
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\current
‪mixed current()
Definition: LoadedExtensionsArray.php:139
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\offsetSet
‪offsetSet($offset, $value)
Definition: LoadedExtensionsArray.php:82
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\count
‪int count()
Definition: LoadedExtensionsArray.php:128
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\toArray
‪array toArray()
Definition: LoadedExtensionsArray.php:215
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\$loadedExtensionArrayElementCache
‪array $loadedExtensionArrayElementCache
Definition: LoadedExtensionsArray.php:30
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\$packageManager
‪TYPO3 CMS Core Package PackageManager $packageManager
Definition: LoadedExtensionsArray.php:26
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\offsetExists
‪bool offsetExists($offset)
Definition: LoadedExtensionsArray.php:51
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\next
‪next()
Definition: LoadedExtensionsArray.php:149
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\__construct
‪__construct(\TYPO3\CMS\Core\Package\PackageManager $packageManager)
Definition: LoadedExtensionsArray.php:39
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\rewind
‪rewind()
Definition: LoadedExtensionsArray.php:187
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\key
‪mixed key()
Definition: LoadedExtensionsArray.php:166
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\$iteratorPosition
‪string $iteratorPosition
Definition: LoadedExtensionsArray.php:34
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\offsetUnset
‪offsetUnset($offset)
Definition: LoadedExtensionsArray.php:94
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\valid
‪bool valid()
Definition: LoadedExtensionsArray.php:177
‪TYPO3\CMS\Core\Compatibility
Definition: LoadedExtensionArrayElement.php:2
‪TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray\serialize
‪string serialize()
Definition: LoadedExtensionsArray.php:105