1<?php
2
3
4
5
6
7
8
9
10
11
12
13namespace Composer;
14
15use Composer\Semver\VersionParser;
16
17
18
19
20
21
22class InstalledVersions
23{
24private static $installed = array (
25  'root' =>
26  array (
27    'pretty_version' => 'v2.2.0',
28    'version' => '2.2.0.0',
29    'aliases' =>
30    array (
31    ),
32    'reference' => 'dd272db0d0b20a8ca0f4569e3f777bb3bc819b0a',
33    'name' => 'mizunashi-mana/dokuwiki-plugin-mdpage',
34  ),
35  'versions' =>
36  array (
37    'cebe/markdown' =>
38    array (
39      'pretty_version' => '1.2.1',
40      'version' => '1.2.1.0',
41      'aliases' =>
42      array (
43      ),
44      'reference' => '9bac5e971dd391e2802dca5400bbeacbaea9eb86',
45    ),
46    'mizunashi-mana/dokuwiki-plugin-mdpage' =>
47    array (
48      'pretty_version' => 'v2.2.0',
49      'version' => '2.2.0.0',
50      'aliases' =>
51      array (
52      ),
53      'reference' => 'dd272db0d0b20a8ca0f4569e3f777bb3bc819b0a',
54    ),
55    'symfony/polyfill-ctype' =>
56    array (
57      'pretty_version' => 'v1.20.0',
58      'version' => '1.20.0.0',
59      'aliases' =>
60      array (
61      ),
62      'reference' => 'f4ba089a5b6366e453971d3aad5fe8e897b37f41',
63    ),
64  ),
65);
66
67
68
69
70
71
72
73public static function getInstalledPackages()
74{
75return array_keys(self::$installed['versions']);
76}
77
78
79
80
81
82
83
84
85
86public static function isInstalled($packageName)
87{
88return isset(self::$installed['versions'][$packageName]);
89}
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104public static function satisfies(VersionParser $parser, $packageName, $constraint)
105{
106$constraint = $parser->parseConstraints($constraint);
107$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
108
109return $provided->matches($constraint);
110}
111
112
113
114
115
116
117
118
119
120
121public static function getVersionRanges($packageName)
122{
123if (!isset(self::$installed['versions'][$packageName])) {
124throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
125}
126
127$ranges = array();
128if (isset(self::$installed['versions'][$packageName]['pretty_version'])) {
129$ranges[] = self::$installed['versions'][$packageName]['pretty_version'];
130}
131if (array_key_exists('aliases', self::$installed['versions'][$packageName])) {
132$ranges = array_merge($ranges, self::$installed['versions'][$packageName]['aliases']);
133}
134if (array_key_exists('replaced', self::$installed['versions'][$packageName])) {
135$ranges = array_merge($ranges, self::$installed['versions'][$packageName]['replaced']);
136}
137if (array_key_exists('provided', self::$installed['versions'][$packageName])) {
138$ranges = array_merge($ranges, self::$installed['versions'][$packageName]['provided']);
139}
140
141return implode(' || ', $ranges);
142}
143
144
145
146
147
148public static function getVersion($packageName)
149{
150if (!isset(self::$installed['versions'][$packageName])) {
151throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
152}
153
154if (!isset(self::$installed['versions'][$packageName]['version'])) {
155return null;
156}
157
158return self::$installed['versions'][$packageName]['version'];
159}
160
161
162
163
164
165public static function getPrettyVersion($packageName)
166{
167if (!isset(self::$installed['versions'][$packageName])) {
168throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
169}
170
171if (!isset(self::$installed['versions'][$packageName]['pretty_version'])) {
172return null;
173}
174
175return self::$installed['versions'][$packageName]['pretty_version'];
176}
177
178
179
180
181
182public static function getReference($packageName)
183{
184if (!isset(self::$installed['versions'][$packageName])) {
185throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
186}
187
188if (!isset(self::$installed['versions'][$packageName]['reference'])) {
189return null;
190}
191
192return self::$installed['versions'][$packageName]['reference'];
193}
194
195
196
197
198
199public static function getRootPackage()
200{
201return self::$installed['root'];
202}
203
204
205
206
207
208
209
210public static function getRawData()
211{
212return self::$installed;
213}
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233public static function reload($data)
234{
235self::$installed = $data;
236}
237}
238