[BUGFIX] Remove unused if in PasswordHashing
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Compatibility / LoadedExtensionArrayElement.php
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
17 use TYPO3\CMS\Core\Core\Environment;
18 use TYPO3\CMS\Core\Package\PackageInterface;
19
20 /**
21 * Class to simulate the "old" extension information array element
22 *
23 * @internal
24 */
25 class LoadedExtensionArrayElement implements \IteratorAggregate, \ArrayAccess, \Serializable, \Countable
26 {
27 /**
28 * @var PackageInterface Instance of package manager
29 */
30 protected $package;
31
32 /**
33 * @var array List of relevant extension files
34 */
35 protected $extensionFilesToCheckFor = [
36 'ext_localconf.php',
37 'ext_tables.php',
38 'ext_tables.sql',
39 'ext_tables_static+adt.sql',
40 'ext_typoscript_constants.typoscript',
41 'ext_typoscript_setup.typoscript',
42 'ext_typoscript_constants.txt',
43 'ext_typoscript_setup.txt'
44 ];
45
46 /**
47 * @var array Final extension information
48 */
49 protected $extensionInformation = [];
50
51 /**
52 * Constructor builds compatibility API
53 *
54 * @param PackageInterface $package
55 */
56 public function __construct(PackageInterface $package)
57 {
58 $this->package = $package;
59 $this->initializeBasicExtensionInformation();
60 $this->initializeExtensionFiles();
61 $this->initializeExtensionIcon();
62 }
63
64 /**
65 * Create main information
66 */
67 protected function initializeBasicExtensionInformation()
68 {
69 $pathSite = Environment::getPublicPath() . '/';
70 $pathSiteLength = strlen($pathSite);
71 $absolutePackagePath = $this->package->getPackagePath();
72 if (strpos($absolutePackagePath, $pathSite) === 0) {
73 $relativePackagePathToPathSite = substr($absolutePackagePath, $pathSiteLength);
74 $relativePackagePathToPathSiteSegments = explode('/', $relativePackagePathToPathSite);
75 $packageType = null;
76 // Determine if extension is installed locally, globally or system (in this order)
77 switch (implode('/', array_slice($relativePackagePathToPathSiteSegments, 0, 2))) {
78 case 'typo3conf/ext':
79 $packageType = 'L';
80 break;
81 case TYPO3_mainDir . 'ext':
82 $packageType = 'G';
83 break;
84 case TYPO3_mainDir . 'sysext':
85 $packageType = 'S';
86 break;
87 case 'typo3temp/var/tests/test_ext':
88 $packageType = 'T';
89 break;
90 }
91 if ($packageType !== null) {
92 $this->extensionInformation['type'] = $packageType;
93 }
94 }
95 }
96
97 /**
98 * Initialize extension icon
99 */
100 protected function initializeExtensionIcon()
101 {
102 $this->extensionInformation['ext_icon'] = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getExtensionIcon($this->package->getPackagePath());
103 }
104
105 /**
106 * Register found files in extension array if extension was found
107 */
108 protected function initializeExtensionFiles()
109 {
110 foreach ($this->extensionFilesToCheckFor as $fileName) {
111 $absolutePathToFile = $this->package->getPackagePath() . $fileName;
112 if (@file_exists($absolutePathToFile)) {
113 $this->extensionInformation[$fileName] = $absolutePathToFile;
114 }
115 }
116 }
117
118 /**
119 * Retrieve an external iterator
120 *
121 * @link http://php.net/manual/en/iteratoraggregate.getiterator.php
122 * @return \Traversable An instance of an object implementing Iterator or Traversable
123 */
124 public function getIterator()
125 {
126 return new \ArrayIterator($this->extensionInformation);
127 }
128
129 /**
130 * Whether an offset exists
131 *
132 * @link http://php.net/manual/en/arrayaccess.offsetexists.php
133 * @param mixed $offset An offset to check for.
134 * @return bool TRUE on success or FALSE on failure.
135 */
136 public function offsetExists($offset)
137 {
138 return isset($this->extensionInformation[$offset]);
139 }
140
141 /**
142 * Offset to retrieve
143 *
144 * @link http://php.net/manual/en/arrayaccess.offsetget.php
145 * @param mixed $offset The offset to retrieve.
146 * @return mixed Can return all value types.
147 */
148 public function offsetGet($offset)
149 {
150 return $this->extensionInformation[$offset];
151 }
152
153 /**
154 * Offset to set
155 *
156 * @link http://php.net/manual/en/arrayaccess.offsetset.php
157 * @param mixed $offset The offset to assign the value to.
158 * @param mixed $value The value to set.
159 * @throws \InvalidArgumentException
160 */
161 public function offsetSet($offset, $value)
162 {
163 throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915115);
164 }
165
166 /**
167 * Offset to unset
168 *
169 * @link http://php.net/manual/en/arrayaccess.offsetunset.php
170 * @param mixed $offset The offset to unset.
171 * @throws \InvalidArgumentException
172 */
173 public function offsetUnset($offset)
174 {
175 throw new \InvalidArgumentException('The array $GLOBALS[\'TYPO3_LOADED_EXT\'] may not be modified.', 1361915206);
176 }
177
178 /**
179 * String representation of object
180 *
181 * @link http://php.net/manual/en/serializable.serialize.php
182 * @return string the string representation of the object or null
183 */
184 public function serialize()
185 {
186 return serialize($this->extensionInformation);
187 }
188
189 /**
190 * Constructs the object
191 *
192 * @link http://php.net/manual/en/serializable.unserialize.php
193 * @param string $serialized The string representation of the object.
194 * @return mixed the original value unserialized.
195 */
196 public function unserialize($serialized)
197 {
198 $this->extensionInformation = unserialize($serialized);
199 }
200
201 /**
202 * Count elements of an object
203 *
204 * @link http://php.net/manual/en/countable.count.php
205 * @return int The custom count as an integer. The return value is cast to an integer.
206 */
207 public function count()
208 {
209 return count($this->extensionInformation);
210 }
211
212 /**
213 * @return array
214 */
215 public function toArray()
216 {
217 return iterator_to_array($this);
218 }
219 }