Completed
Push — master ( 471d20...bd01a5 )
by
unknown
16:06 queued 43s
created

Extension::getState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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