Relation.php 5.09 KB
Newer Older
1
<?php
2

3 4
namespace T3o\TerFe2\Domain\Model;

5 6
/*
 * This file is part of the TYPO3 CMS project.
7
 *
8 9 10
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
11
 *
12 13
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
14
 *
15 16
 * The TYPO3 project - inspiring people to share!
 */
17

18
use T3o\TerFe2\Utility\VersionUtility;
19

20 21 22
/**
 * Any type of relation of an extension
 */
23
class Relation extends \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject
24 25 26
{
    /**
     * Dependancy, conflict or suggest
27
     *
28 29 30
     * @var string
     * @validate NotEmpty
     */
31
    protected $relationType = '';
32 33 34

    /**
     * Extension key, php, mysql or something else
35
     *
36 37 38
     * @var string
     * @validate NotEmpty
     */
39
    protected $relationKey = '';
40 41 42

    /**
     * Minimum required version for this Relation
43
     *
44
     * @var int
45
     */
46
    protected $minimumVersion = 0;
47 48 49

    /**
     * Maximum allowed version for this Relation
50
     *
51
     * @var int
52
     */
53
    protected $maximumVersion = 0;
54 55 56

    /**
     * Related extension if in TER
57
     *
58
     * @var \T3o\TerFe2\Domain\Model\Extension $relatedExtension
59
     */
60
    protected $relatedExtension;
61 62 63 64 65 66

    /**
     * Setter for relationType
     *
     * @param string $relationType Dependancy, conflict or suggest
     */
67
    public function setRelationType(string $relationType)
68 69 70 71 72 73 74 75 76
    {
        $this->relationType = $relationType;
    }

    /**
     * Getter for relationType
     *
     * @return string Dependancy, conflict or suggest
     */
77
    public function getRelationType(): string
78 79 80 81 82 83 84 85 86
    {
        return $this->relationType;
    }

    /**
     * Setter for relationKey
     *
     * @param string $relationKey extension key, php, mysql or something else
     */
87
    public function setRelationKey(string $relationKey)
88 89 90 91 92 93 94 95 96
    {
        $this->relationKey = $relationKey;
    }

    /**
     * Getter for relationKey
     *
     * @return string extension key, php, mysql or something else
     */
97
    public function getRelationKey(): string
98 99 100 101
    {
        if (empty($this->relationKey)) {
            return '';
        }
102

103 104 105 106 107 108
        return strtolower(trim($this->relationKey));
    }

    /**
     * Setter for minimumVersion
     *
109
     * @param int $minimumVersion Minimum required version
110
     */
111
    public function setMinimumVersion(int $minimumVersion)
112 113 114 115 116 117 118
    {
        $this->minimumVersion = $minimumVersion;
    }

    /**
     * Getter for minimumVersion
     *
119
     * @return int Minimum required version
120
     */
121
    public function getMinimumVersion(): int
122
    {
123
        return $this->minimumVersion;
124 125 126 127 128
    }

    /**
     * Setter for maximumVersion
     *
129
     * @param int $maximumVersion Maximum allowed version
130
     */
131
    public function setMaximumVersion(int $maximumVersion)
132 133 134 135 136 137 138
    {
        $this->maximumVersion = $maximumVersion;
    }

    /**
     * Getter for maximumVersion
     *
139
     * @return int Maximum allowed version
140
     */
141
    public function getMaximumVersion(): int
142
    {
143
        return $this->maximumVersion;
144 145 146 147 148
    }

    /**
     * Setter for relatedExtension
     *
149
     * @param \T3o\TerFe2\Domain\Model\Extension $relatedExtension
150
     */
151
    public function setRelatedExtension(Extension $relatedExtension = null)
152 153 154 155 156 157 158
    {
        $this->relatedExtension = $relatedExtension;
    }

    /**
     * Getter for relatedExtension
     *
159
     * @return \T3o\TerFe2\Domain\Model\Extension
160
     */
161
    public function getRelatedExtension()
162 163 164 165 166 167 168 169 170
    {
        return $this->relatedExtension;
    }

    /**
     * Returns minumum and maximum version as string
     *
     * @return string Version
     */
171
    public function getVersionString(): string
172
    {
173
        $version = [];
174 175

        if (!empty($this->minimumVersion)) {
176
            $version[] = VersionUtility::versionFromInteger($this->minimumVersion);
177 178 179
        }

        if (!empty($this->maximumVersion)) {
180
            $version[] = VersionUtility::versionFromInteger($this->maximumVersion);
181 182
        }

183
        return !empty($version) ? implode(' - ', $version) : '';
184 185 186 187 188 189 190
    }

    /**
     * Get software type
     *
     * @return string core, system or extension
     */
191
    public function getType(): string
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
    {
        $key = $this->getRelationKey();

        if (empty($key)) {
            return '';
        }

        if ($key === 'cms' || $key === 'typo3') {
            return 'core';
        }

        if ($key === 'php') {
            return 'system';
        }

        return 'extension';
    }

    /**
     * Is core relation
     *
213
     * @return bool TRUE if related to core
214
     */
215
    public function getIsCore(): bool
216
    {
217
        return $this->getType() === 'core';
218 219 220 221 222
    }

    /**
     * Is system relation
     *
223
     * @return bool TRUE if related to system
224
     */
225
    public function getIsSystem(): bool
226
    {
227
        return $this->getType() === 'system';
228 229 230 231 232
    }

    /**
     * Is extension relation
     *
233
     * @return bool TRUE if related to an extension
234
     */
235
    public function getIsExtension(): bool
236
    {
237
        return $this->getType() === 'extension';
238 239
    }
}