VersionUtility.php 1.96 KB
Newer Older
1
<?php
2 3
namespace T3o\TerFe2\Utility;

4 5
/*
 * This file is part of the TYPO3 CMS project.
6
 *
7 8 9
 * 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.
10
 *
11 12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14 15
 * The TYPO3 project - inspiring people to share!
 */
16

17 18 19
/**
 * Utilities to manage versions
 */
20
class VersionUtility
21
{
22

23 24 25
    /**
     * Build version from integer
     *
26
     * @param int $version The numeric version
27 28 29 30 31 32 33 34 35
     * @return string Version string
     */
    public static function versionFromInteger($version)
    {
        if (empty($version)) {
            return '';
        }

        $versionString = str_pad($version, 9, '0', STR_PAD_LEFT);
36
        $parts = [
37 38 39
            substr($versionString, 0, 3),
            substr($versionString, 3, 3),
            substr($versionString, 6, 3)
40
        ];
41 42
        return intval($parts[0]) . '.' . intval($parts[1]) . '.' . intval($parts[2]);
    }
43 44

    /**
45
     * @param \T3o\TerFe2\Domain\Model\Extension $extension
46 47 48
     * @param int $mainVersion
     * @return bool
     */
49
    public static function doesExtensionSupportTypo3Version(\T3o\TerFe2\Domain\Model\Extension $extension, int $mainVersion): bool
50
    {
51
        foreach ($extension->getVersions() as $version) {
52
            if ($version->hasTypo3Dependency() === false || $version->isLive() === false) {
53 54 55 56 57
                continue;
            }

            // reset from e.g. 7.6.21 to 7.6.0 for valid check
            $resetMinimumVersion = (int)($version->getTypo3Dependency()->getMinimumVersion() / 1000) * 1000;
58

59 60 61 62 63 64
            $supportsTypo3Version = $resetMinimumVersion <= $mainVersion && $version->getTypo3Dependency()->getMaximumVersion() >= $mainVersion;

            if ($supportsTypo3Version) {
                return true;
            }
        }
65

66
        return false;
67
    }
68
}