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