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