25
25
use Composer \Repository \RepositorySet ;
26
26
use Composer \Semver \Constraint \MultiConstraint ;
27
27
use Composer \Semver \Intervals ;
28
+ use Composer \Semver \VersionParser ;
28
29
use Symfony \Flex \Unpack \Operation ;
29
30
use Symfony \Flex \Unpack \Result ;
30
31
@@ -33,12 +34,14 @@ class Unpacker
33
34
private $ composer ;
34
35
private $ resolver ;
35
36
private $ dryRun ;
37
+ private $ versionParser ;
36
38
37
39
public function __construct (Composer $ composer , PackageResolver $ resolver , bool $ dryRun )
38
40
{
39
41
$ this ->composer = $ composer ;
40
42
$ this ->resolver = $ resolver ;
41
43
$ this ->dryRun = $ dryRun ;
44
+ $ this ->versionParser = new VersionParser ();
42
45
}
43
46
44
47
public function unpack (Operation $ op , Result $ result = null , &$ links = []): Result
@@ -101,7 +104,7 @@ public function unpack(Operation $op, Result $result = null, &$links = []): Resu
101
104
$ linkType = $ package ['dev ' ] ? 'require-dev ' : 'require ' ;
102
105
103
106
if (isset ($ links [$ linkName ])) {
104
- $ links [$ linkName ]['constraints ' ][] = $ constraint ;
107
+ $ links [$ linkName ]['constraints ' ][] = $ this -> versionParser -> parseConstraints ( $ constraint) ;
105
108
if ('require ' === $ linkType ) {
106
109
$ links [$ linkName ]['type ' ] = 'require ' ;
107
110
}
@@ -138,16 +141,16 @@ public function unpack(Operation $op, Result $result = null, &$links = []): Resu
138
141
139
142
// removes package from "require-dev", because it will be moved to "require"
140
143
// save stored constraint
141
- $ link ['constraints ' ][] = $ jsonStored ['require-dev ' ][$ link ['name ' ]];
144
+ $ link ['constraints ' ][] = $ this -> versionParser -> parseConstraints ( $ jsonStored ['require-dev ' ][$ link ['name ' ]]) ;
142
145
$ jsonManipulator ->removeSubNode ('require-dev ' , $ link ['name ' ]);
143
146
}
144
147
145
148
$ constraint = class_exists (Intervals::class, false )
146
- ? Intervals::compactConstraint (MultiConstraint::create ($ link ['constraints ' ]))-> getPrettyString ()
149
+ ? Intervals::compactConstraint (MultiConstraint::create ($ link ['constraints ' ]))
147
150
: end ($ link ['constraints ' ])
148
151
;
149
152
150
- if (!$ jsonManipulator ->addLink ($ link ['type ' ], $ link ['name ' ], $ constraint , $ op ->shouldSort ())) {
153
+ if (!$ jsonManipulator ->addLink ($ link ['type ' ], $ link ['name ' ], $ constraint-> getPrettyString () , $ op ->shouldSort ())) {
151
154
throw new \RuntimeException (sprintf ('Unable to unpack package "%s". ' , $ link ['name ' ]));
152
155
}
153
156
}
0 commit comments