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