1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright (c) 2014-2017 brian ridley |
5
|
|
|
* @author brian ridley <[email protected]> |
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ptlis\SemanticVersion\VersionRange; |
13
|
|
|
|
14
|
|
|
use ptlis\SemanticVersion\Comparator\ComparatorInterface; |
15
|
|
|
use ptlis\SemanticVersion\Version\VersionInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Simple version number & comparator. |
19
|
|
|
*/ |
20
|
|
|
final class ComparatorVersion implements VersionRangeInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var ComparatorInterface |
24
|
|
|
*/ |
25
|
|
|
private $comparator; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var VersionInterface |
29
|
|
|
*/ |
30
|
|
|
private $version; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Constructor. |
35
|
|
|
* |
36
|
|
|
* @param ComparatorInterface $comparator |
37
|
|
|
* @param VersionInterface $version |
38
|
|
|
*/ |
39
|
3 |
|
public function __construct(ComparatorInterface $comparator, VersionInterface $version) |
40
|
|
|
{ |
41
|
3 |
|
$this->comparator = $comparator; |
42
|
3 |
|
$this->version = $version; |
43
|
3 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritDoc} |
47
|
|
|
*/ |
48
|
1 |
|
public function isSatisfiedBy(VersionInterface $version) |
49
|
|
|
{ |
50
|
1 |
|
return $this->comparator->compare($version, $this->version); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
*/ |
56
|
1 |
|
public function __toString() |
57
|
|
|
{ |
58
|
1 |
|
return $this->comparator . $this->version; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the comparator. |
63
|
|
|
* |
64
|
|
|
* @todo Remove this hack - temporary mechanism to allow for extraction of comparator info |
65
|
|
|
* |
66
|
|
|
* @return ComparatorInterface |
67
|
|
|
*/ |
68
|
1 |
|
public function getComparator() |
69
|
|
|
{ |
70
|
1 |
|
return $this->comparator; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the version. |
75
|
|
|
* |
76
|
|
|
* @todo Remove this hack - temporary mechanism to allow for extraction of version info |
77
|
|
|
* |
78
|
|
|
* @return VersionInterface |
79
|
|
|
*/ |
80
|
1 |
|
public function getVersion() |
81
|
|
|
{ |
82
|
1 |
|
return $this->version; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|