[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Classes / Domain / Model / Extension.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Domain\Model;
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 * Main extension model
18 *
19 * @author Susanne Moog <typo3@susannemoog.de>
20 */
21 class Extension extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
22
23 /**
24 * Category index for distributions
25 */
26 const DISTRIBUTION_CATEGORY = 10;
27
28 /**
29 * Contains default categories.
30 *
31 * @var array
32 */
33 static protected $defaultCategories = array(
34 0 => 'be',
35 1 => 'module',
36 2 => 'fe',
37 3 => 'plugin',
38 4 => 'misc',
39 5 => 'services',
40 6 => 'templates',
41 8 => 'doc',
42 9 => 'example',
43 Extension::DISTRIBUTION_CATEGORY => 'distribution'
44 );
45
46 /**
47 * Contains default states.
48 *
49 * @var array
50 */
51 static protected $defaultStates = array(
52 0 => 'alpha',
53 1 => 'beta',
54 2 => 'stable',
55 3 => 'experimental',
56 4 => 'test',
57 5 => 'obsolete',
58 6 => 'excludeFromUpdates',
59 999 => 'n/a'
60 );
61
62 /**
63 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
64 * @inject
65 */
66 protected $objectManager;
67
68 /**
69 * @var string
70 */
71 protected $extensionKey = '';
72
73 /**
74 * @var string
75 */
76 protected $version = '';
77
78 /**
79 * @var int
80 */
81 protected $integerVersion = 0;
82
83 /**
84 * @var string
85 */
86 protected $title = '';
87
88 /**
89 * @var string
90 */
91 protected $description = '';
92
93 /**
94 * @var int
95 */
96 protected $state = 0;
97
98 /**
99 * @var int
100 */
101 protected $category = 0;
102
103 /**
104 * @var \DateTime
105 */
106 protected $lastUpdated;
107
108 /**
109 * @var string
110 */
111 protected $updateComment = '';
112
113 /**
114 * @var string
115 */
116 protected $authorName = '';
117
118 /**
119 * @var string
120 */
121 protected $authorEmail = '';
122
123 /**
124 * @var bool
125 */
126 protected $currentVersion = FALSE;
127
128 /**
129 * @var string
130 */
131 protected $md5hash = '';
132
133 /**
134 * @var int
135 */
136 protected $reviewState;
137
138 /**
139 * @var int
140 */
141 protected $alldownloadcounter;
142
143 /**
144 * @var string
145 */
146 protected $serializedDependencies = '';
147
148 /**
149 * @var \SplObjectStorage<Tx_Extensionmanager_Utility_Dependency>
150 */
151 protected $dependencies = NULL;
152
153 /**
154 * @internal
155 * @var int
156 */
157 protected $position = 0;
158
159 /**
160 * @param string $authorEmail
161 * @return void
162 */
163 public function setAuthorEmail($authorEmail) {
164 $this->authorEmail = $authorEmail;
165 }
166
167 /**
168 * @return string
169 */
170 public function getAuthorEmail() {
171 return $this->authorEmail;
172 }
173
174 /**
175 * @param string $authorName
176 * @return void
177 */
178 public function setAuthorName($authorName) {
179 $this->authorName = $authorName;
180 }
181
182 /**
183 * @return string
184 */
185 public function getAuthorName() {
186 return $this->authorName;
187 }
188
189 /**
190 * @param int $category
191 * @return void
192 */
193 public function setCategory($category) {
194 $this->category = $category;
195 }
196
197 /**
198 * @return int
199 */
200 public function getCategory() {
201 return $this->category;
202 }
203
204 /**
205 * Get Category String
206 *
207 * @return string
208 */
209 public function getCategoryString() {
210 $categoryString = '';
211 if (isset(self::$defaultCategories[$this->getCategory()])) {
212 $categoryString = self::$defaultCategories[$this->getCategory()];
213 }
214 return $categoryString;
215 }
216
217 /**
218 * Returns category index from a given string or a integer.
219 * Fallback to 4 - 'misc' in case string is not found or integer ist out of range.
220 *
221 * @param string|int $category Category string or integer
222 * @return int Valid category index
223 */
224 public function getCategoryIndexFromStringOrNumber($category) {
225 $categoryIndex = 4;
226 if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($category)) {
227 $categoryIndex = (int)$category;
228 if ($categoryIndex < 0 || $categoryIndex > 10) {
229 $categoryIndex = 4;
230 }
231 } elseif (is_string($category)) {
232 $categoryIndex = array_search($category, self::$defaultCategories);
233 if ($categoryIndex === FALSE) {
234 $categoryIndex = 4;
235 }
236 }
237 return $categoryIndex;
238 }
239
240 /**
241 * @param string $description
242 * @return void
243 */
244 public function setDescription($description) {
245 $this->description = $description;
246 }
247
248 /**
249 * @return string
250 */
251 public function getDescription() {
252 return $this->description;
253 }
254
255 /**
256 * @param string $extensionKey
257 * @return void
258 */
259 public function setExtensionKey($extensionKey) {
260 $this->extensionKey = $extensionKey;
261 }
262
263 /**
264 * @return string
265 */
266 public function getExtensionKey() {
267 return $this->extensionKey;
268 }
269
270 /**
271 * @param \DateTime $lastUpdated
272 * @return void
273 */
274 public function setLastUpdated(\DateTime $lastUpdated) {
275 $this->lastUpdated = $lastUpdated;
276 }
277
278 /**
279 * @return \DateTime
280 */
281 public function getLastUpdated() {
282 return $this->lastUpdated;
283 }
284
285 /**
286 * @param int $state
287 * @return void
288 */
289 public function setState($state) {
290 $this->state = $state;
291 }
292
293 /**
294 * @return int
295 */
296 public function getState() {
297 return $this->state;
298 }
299
300 /**
301 * Get State string
302 *
303 * @return string
304 */
305 public function getStateString() {
306 $stateString = '';
307 if (isset(self::$defaultStates[$this->getState()])) {
308 $stateString = self::$defaultStates[$this->getState()];
309 }
310 return $stateString;
311 }
312
313 /**
314 * Returns either array with all default states or index/title
315 * of a state entry.
316 *
317 * @param mixed $state state title or state index
318 * @return mixed
319 */
320 public function getDefaultState($state = NULL) {
321 $defaultState = '';
322 if (is_null($state)) {
323 $defaultState = self::$defaultStates;
324 } else {
325 if (is_string($state)) {
326 $stateIndex = array_search(strtolower($state), self::$defaultStates);
327 if ($stateIndex === FALSE) {
328 // default state
329 $stateIndex = 999;
330 }
331 $defaultState = $stateIndex;
332 } else {
333 if (is_int($state) && $state >= 0) {
334 if (array_key_exists($state, self::$defaultStates)) {
335 $stateTitle = self::$defaultStates[$state];
336 } else {
337 // default state
338 $stateTitle = 'n/a';
339 }
340 $defaultState = $stateTitle;
341 }
342 }
343 }
344 return $defaultState;
345 }
346
347 /**
348 * @param string $title
349 * @return void
350 */
351 public function setTitle($title) {
352 $this->title = $title;
353 }
354
355 /**
356 * @return string
357 */
358 public function getTitle() {
359 return $this->title;
360 }
361
362 /**
363 * @param string $updateComment
364 * @return void
365 */
366 public function setUpdateComment($updateComment) {
367 $this->updateComment = $updateComment;
368 }
369
370 /**
371 * @return string
372 */
373 public function getUpdateComment() {
374 return $this->updateComment;
375 }
376
377 /**
378 * @param string $version
379 * @return void
380 */
381 public function setVersion($version) {
382 $this->version = $version;
383 }
384
385 /**
386 * @return string
387 */
388 public function getVersion() {
389 return $this->version;
390 }
391
392 /**
393 * @param bool $currentVersion
394 * @return void
395 */
396 public function setCurrentVersion($currentVersion) {
397 $this->currentVersion = $currentVersion;
398 }
399
400 /**
401 * @return bool
402 */
403 public function getCurrentVersion() {
404 return $this->currentVersion;
405 }
406
407 /**
408 * @param string $md5hash
409 * @return void
410 */
411 public function setMd5hash($md5hash) {
412 $this->md5hash = $md5hash;
413 }
414
415 /**
416 * @return string
417 */
418 public function getMd5hash() {
419 return $this->md5hash;
420 }
421
422 /**
423 * Possible install pathes
424 *
425 * @static
426 * @return array
427 */
428 static public function returnInstallPaths() {
429 $installPaths = array(
430 'System' => PATH_typo3 . 'sysext/',
431 'Global' => PATH_typo3 . 'ext/',
432 'Local' => PATH_typo3conf . 'ext/'
433 );
434 return $installPaths;
435 }
436
437 /**
438 * Allowed install pathes
439 *
440 * @static
441 * @return array
442 */
443 static public function returnAllowedInstallPaths() {
444 $installPaths = self::returnInstallPaths();
445 if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowSystemInstall'])) {
446 unset($installPaths['System']);
447 }
448 if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowGlobalInstall'])) {
449 unset($installPaths['Global']);
450 }
451 if (empty($GLOBALS['TYPO3_CONF_VARS']['EXT']['allowLocalInstall'])) {
452 unset($installPaths['Local']);
453 }
454 return $installPaths;
455 }
456
457 /**
458 * Allowed install names: System, Global, Local
459 *
460 * @static
461 * @return array
462 */
463 static public function returnAllowedInstallTypes() {
464 $installPaths = self::returnAllowedInstallPaths();
465 return array_keys($installPaths);
466 }
467
468 /**
469 * @param string $dependencies
470 * @return void
471 */
472 public function setSerializedDependencies($dependencies) {
473 $this->serializedDependencies = $dependencies;
474 }
475
476 /**
477 * @return string
478 */
479 public function getSerializedDependencies() {
480 return $this->serializedDependencies;
481 }
482
483 /**
484 * @param \SplObjectStorage $dependencies
485 * @return void
486 */
487 public function setDependencies($dependencies) {
488 $this->dependencies = $dependencies;
489 }
490
491 /**
492 * @return \SplObjectStorage
493 */
494 public function getDependencies() {
495 if (!is_object($this->dependencies)) {
496 /** @var $extensionModelUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
497 $extensionModelUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class);
498 $this->setDependencies($extensionModelUtility->convertDependenciesToObjects($this->getSerializedDependencies()));
499 }
500 return $this->dependencies;
501 }
502
503 /**
504 * @param \TYPO3\CMS\Extensionmanager\Domain\Model\Dependency $dependency
505 * @return void
506 */
507 public function addDependency(\TYPO3\CMS\Extensionmanager\Domain\Model\Dependency $dependency) {
508 $this->dependencies->attach($dependency);
509 }
510
511 /**
512 * @param int $integerVersion
513 * @return void
514 */
515 public function setIntegerVersion($integerVersion) {
516 $this->integerVersion = $integerVersion;
517 }
518
519 /**
520 * @return int
521 */
522 public function getIntegerVersion() {
523 return $this->integerVersion;
524 }
525
526 /**
527 * @param int $reviewState
528 * @return void
529 */
530 public function setReviewState($reviewState) {
531 $this->reviewState = $reviewState;
532 }
533
534 /**
535 * @return int
536 */
537 public function getReviewState() {
538 return $this->reviewState;
539 }
540
541 /**
542 * @param int $position
543 * @return void
544 */
545 public function setPosition($position) {
546 $this->position = $position;
547 }
548
549 /**
550 * @return int
551 */
552 public function getPosition() {
553 return $this->position;
554 }
555
556 /**
557 * @param int $alldownloadcounter
558 */
559 public function setAlldownloadcounter($alldownloadcounter) {
560 $this->alldownloadcounter = $alldownloadcounter;
561 }
562
563 /**
564 * @return int
565 */
566 public function getAlldownloadcounter() {
567 return $this->alldownloadcounter;
568 }
569
570 }