@@ -31,46 +31,20 @@ public function __construct(Downloader $downloader)
31
31
32
32
public function resolve (array $ arguments = [], bool $ isRequire = false ): array
33
33
{
34
- $ versionParser = new VersionParser ();
35
-
36
- // first pass split on : and = to separate package names and versions
37
- $ explodedArguments = [];
38
- foreach ($ arguments as $ argument ) {
34
+ // first pass split on : and = to resolve package names
35
+ $ packages = [];
36
+ foreach ($ arguments as $ i => $ argument ) {
39
37
if ((false !== $ pos = strpos ($ argument , ': ' )) || (false !== $ pos = strpos ($ argument , '= ' ))) {
40
- $ explodedArguments [] = substr ($ argument , 0 , $ pos );
41
- $ explodedArguments [] = substr ($ argument , $ pos + 1 );
38
+ $ package = $ this ->resolvePackageName (substr ($ argument , 0 , $ pos ), $ i );
39
+ $ version = substr ($ argument , $ pos + 1 );
40
+ $ packages [] = $ package .': ' .$ version ;
42
41
} else {
43
- $ explodedArguments [] = $ argument ;
42
+ $ packages [] = $ this -> resolvePackageName ( $ argument, $ i ) ;
44
43
}
45
44
}
46
45
47
- // second pass to resolve package names
48
- $ packages = [];
49
- foreach ($ explodedArguments as $ i => $ argument ) {
50
- if (false === strpos ($ argument , '/ ' ) && !preg_match (PlatformRepository::PLATFORM_PACKAGE_REGEX , $ argument ) && !preg_match ('{(?<=[a-z0-9_/-])\*|\*(?=[a-z0-9_/-])}i ' , $ argument ) && !\in_array ($ argument , ['mirrors ' , 'nothing ' ])) {
51
- if (null === self ::$ aliases ) {
52
- self ::$ aliases = $ this ->downloader ->get ('/aliases.json ' )->getBody ();
53
- }
54
-
55
- if (isset (self ::$ aliases [$ argument ])) {
56
- $ argument = self ::$ aliases [$ argument ];
57
- } else {
58
- // is it a version or an alias that does not exist?
59
- try {
60
- $ versionParser ->parseConstraints ($ argument );
61
- } catch (\UnexpectedValueException $ e ) {
62
- // is it a special Symfony version?
63
- if (!\in_array ($ argument , self ::$ SYMFONY_VERSIONS , true )) {
64
- $ this ->throwAlternatives ($ argument , $ i );
65
- }
66
- }
67
- }
68
- }
69
-
70
- $ packages [] = $ argument ;
71
- }
72
-
73
- // third pass to resolve versions
46
+ // second pass to resolve versions
47
+ $ versionParser = new VersionParser ();
74
48
$ requires = [];
75
49
foreach ($ versionParser ->parseNameVersionPairs ($ packages ) as $ package ) {
76
50
$ requires [] = $ package ['name ' ].$ this ->parseVersion ($ package ['name ' ], $ package ['version ' ] ?? '' , $ isRequire );
@@ -111,6 +85,34 @@ public function parseVersion(string $package, string $version, bool $isRequire):
111
85
return ': ' .$ version ;
112
86
}
113
87
88
+ private function resolvePackageName (string $ argument , int $ position ): string
89
+ {
90
+ if (false !== strpos ($ argument , '/ ' ) || preg_match (PlatformRepository::PLATFORM_PACKAGE_REGEX , $ argument ) || preg_match ('{(?<=[a-z0-9_/-])\*|\*(?=[a-z0-9_/-])}i ' , $ argument ) || \in_array ($ argument , ['mirrors ' , 'nothing ' ])) {
91
+ return $ argument ;
92
+ }
93
+
94
+ if (null === self ::$ aliases ) {
95
+ self ::$ aliases = $ this ->downloader ->get ('/aliases.json ' )->getBody ();
96
+ }
97
+
98
+ if (isset (self ::$ aliases [$ argument ])) {
99
+ $ argument = self ::$ aliases [$ argument ];
100
+ } else {
101
+ // is it a version or an alias that does not exist?
102
+ try {
103
+ $ versionParser = new VersionParser ();
104
+ $ versionParser ->parseConstraints ($ argument );
105
+ } catch (\UnexpectedValueException $ e ) {
106
+ // is it a special Symfony version?
107
+ if (!\in_array ($ argument , self ::$ SYMFONY_VERSIONS , true )) {
108
+ $ this ->throwAlternatives ($ argument , $ position );
109
+ }
110
+ }
111
+ }
112
+
113
+ return $ argument ;
114
+ }
115
+
114
116
/**
115
117
* @throws \UnexpectedValueException
116
118
*/
0 commit comments