Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types = 1);
2
namespace PharIo\Version;
3
 
4
class VersionConstraintValue {
5
    /** @var VersionNumber */
6
    private $major;
7
 
8
    /** @var VersionNumber */
9
    private $minor;
10
 
11
    /** @var VersionNumber */
12
    private $patch;
13
 
14
    /** @var string */
15
    private $label = '';
16
 
17
    /** @var string */
18
    private $buildMetaData = '';
19
 
20
    /** @var string */
21
    private $versionString = '';
22
 
23
    public function __construct(string $versionString) {
24
        $this->versionString = $versionString;
25
 
26
        $this->parseVersion($versionString);
27
    }
28
 
29
    public function getLabel(): string {
30
        return $this->label;
31
    }
32
 
33
    public function getBuildMetaData(): string {
34
        return $this->buildMetaData;
35
    }
36
 
37
    public function getVersionString(): string {
38
        return $this->versionString;
39
    }
40
 
41
    public function getMajor(): VersionNumber {
42
        return $this->major;
43
    }
44
 
45
    public function getMinor(): VersionNumber {
46
        return $this->minor;
47
    }
48
 
49
    public function getPatch(): VersionNumber {
50
        return $this->patch;
51
    }
52
 
53
    private function parseVersion(string $versionString): void {
54
        $this->extractBuildMetaData($versionString);
55
        $this->extractLabel($versionString);
56
        $this->stripPotentialVPrefix($versionString);
57
 
58
        $versionSegments = \explode('.', $versionString);
59
        $this->major     = new VersionNumber(\is_numeric($versionSegments[0]) ? (int)$versionSegments[0] : null);
60
 
61
        $minorValue = isset($versionSegments[1]) && \is_numeric($versionSegments[1]) ? (int)$versionSegments[1] : null;
62
        $patchValue = isset($versionSegments[2]) && \is_numeric($versionSegments[2]) ? (int)$versionSegments[2] : null;
63
 
64
        $this->minor = new VersionNumber($minorValue);
65
        $this->patch = new VersionNumber($patchValue);
66
    }
67
 
68
    private function extractBuildMetaData(string &$versionString): void {
69
        if (\preg_match('/\+(.*)/', $versionString, $matches) === 1) {
70
            $this->buildMetaData = $matches[1];
71
            $versionString       = \str_replace($matches[0], '', $versionString);
72
        }
73
    }
74
 
75
    private function extractLabel(string &$versionString): void {
76
        if (\preg_match('/-(.*)/', $versionString, $matches) === 1) {
77
            $this->label   = $matches[1];
78
            $versionString = \str_replace($matches[0], '', $versionString);
79
        }
80
    }
81
 
82
    private function stripPotentialVPrefix(string &$versionString): void {
83
        if ($versionString[0] !== 'v') {
84
            return;
85
        }
86
        $versionString = \substr($versionString, 1);
87
    }
88
}