1 | <?php |
||
20 | class StabilityFlags |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var array Current package name => stability mappings |
||
25 | */ |
||
26 | protected $stabilityFlags; |
||
27 | |||
28 | /** |
||
29 | * @var int Current default minimum stability |
||
30 | */ |
||
31 | protected $minimumStability; |
||
32 | |||
33 | /** |
||
34 | * @var string Regex to extract an explict stability flag (eg '@dev') |
||
35 | */ |
||
36 | protected $explicitStabilityRe; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * @param array $stabilityFlags Current package name => stability mappings |
||
41 | * @param int $minimumStability Current default minimum stability |
||
42 | */ |
||
43 | 55 | public function __construct( |
|
44 | array $stabilityFlags = array(), |
||
45 | $minimumStability = BasePackage::STABILITY_STABLE |
||
46 | ) { |
||
47 | 55 | $this->stabilityFlags = $stabilityFlags; |
|
48 | 55 | $this->minimumStability = $this->getStabilityInt($minimumStability); |
|
49 | 55 | $this->explicitStabilityRe = '/^[^@]*?@(' . |
|
50 | 55 | implode('|', array_keys(BasePackage::$stabilities)) . |
|
51 | 55 | ')$/i'; |
|
52 | 55 | } |
|
53 | |||
54 | /** |
||
55 | * Get the stability value for a given string. |
||
56 | * |
||
57 | * @param string $name Stability name |
||
58 | * @return int Stability value |
||
59 | */ |
||
60 | 55 | protected function getStabilityInt($name) |
|
67 | |||
68 | /** |
||
69 | * Extract and merge stability flags from the given collection of |
||
70 | * requires with another collection of stability flags. |
||
71 | * |
||
72 | * @param array $requires New package name => link mappings |
||
73 | * @return array Unified package name => stability mappings |
||
74 | */ |
||
75 | 55 | public function extractAll(array $requires) |
|
97 | |||
98 | |||
99 | /** |
||
100 | * Extract the most unstable explicit stability (eg '@dev') from a version |
||
101 | * specification. |
||
102 | * |
||
103 | * @param string $version |
||
104 | * @return int|null Stability or null if no explict stability found |
||
105 | */ |
||
106 | 55 | protected function getExplicitStability($version) |
|
118 | |||
119 | |||
120 | /** |
||
121 | * Split a version specification into a list of version constraints. |
||
122 | * |
||
123 | * @param string $version |
||
124 | * @return array |
||
125 | */ |
||
126 | 55 | protected function splitConstraints($version) |
|
141 | |||
142 | |||
143 | /** |
||
144 | * Get the stability of a version |
||
145 | * |
||
146 | * @param string $version |
||
147 | * @return int|null Stability or null if STABLE or less than minimum |
||
148 | */ |
||
149 | 15 | protected function getParsedStability($version) |
|
150 | { |
||
151 | // Drop aliasing if used |
||
152 | 15 | $version = preg_replace('/^([^,\s@]+) as .+$/', '$1', $version); |
|
153 | 15 | $stability = $this->getStabilityInt( |
|
154 | 15 | VersionParser::parseStability($version) |
|
155 | 15 | ); |
|
156 | |||
157 | 15 | if ($stability === BasePackage::STABILITY_STABLE || |
|
158 | 15 | $this->minimumStability > $stability |
|
159 | 15 | ) { |
|
160 | // Ignore if 'stable' or more stable than the global |
||
161 | // minimum |
||
162 | $stability = null; |
||
163 | } |
||
164 | |||
165 | 15 | return $stability; |
|
166 | } |
||
167 | |||
168 | |||
169 | /** |
||
170 | * Get the current stability of a given package. |
||
171 | * |
||
172 | * @param string $name |
||
173 | * @return int|null Stability of null if not set |
||
174 | */ |
||
175 | 55 | protected function getCurrentStability($name) |
|
180 | } |
||
181 | // vim:sw=4:ts=4:sts=4:et: |
||
182 |