@@ -42,7 +42,7 @@ public function __construct(Composer $composer, PackageResolver $resolver, bool
42
42
$ this ->versionParser = new VersionParser ();
43
43
}
44
44
45
- public function unpack (Operation $ op , Result $ result = null , &$ links = []): Result
45
+ public function unpack (Operation $ op , Result $ result = null , &$ links = [], bool $ devRequire = false ): Result
46
46
{
47
47
if (null === $ result ) {
48
48
$ result = new Result ();
@@ -69,50 +69,67 @@ public function unpack(Operation $op, Result $result = null, &$links = []): Resu
69
69
continue ;
70
70
}
71
71
72
- $ versionSelector = null ;
72
+ $ requires = [] ;
73
73
foreach ($ pkg ->getRequires () as $ link ) {
74
- if ('php ' === $ link ->getTarget ()) {
75
- continue ;
74
+ $ requires [$ link ->getTarget ()] = $ link ;
75
+ }
76
+ $ devRequires = $ pkg ->getDevRequires ();
77
+
78
+ foreach ($ devRequires as $ i => $ link ) {
79
+ if (!isset ($ requires [$ link ->getTarget ()])) {
80
+ throw new \RuntimeException (sprintf ('Symfony pack "%s" must duplicate all entries from "require-dev" into "require" but entry "%s" was not found. ' , $ package ['name ' ], $ link ->getTarget ()));
76
81
}
82
+ $ devRequires [$ i ] = $ requires [$ link ->getTarget ()];
83
+ unset($ requires [$ link ->getTarget ()]);
84
+ }
77
85
78
- $ constraint = $ link ->getPrettyConstraint ();
79
- $ constraint = substr ($ this ->resolver ->parseVersion ($ link ->getTarget (), $ constraint , !$ package ['dev ' ]), 1 ) ?: $ constraint ;
86
+ $ versionSelector = null ;
87
+ foreach ([$ requires , $ devRequires ] as $ dev => $ requires ) {
88
+ $ dev = $ dev ?: $ devRequire ?: $ package ['dev ' ];
80
89
81
- if ($ subPkg = $ localRepo ->findPackage ($ link ->getTarget (), '* ' )) {
82
- if ('symfony-pack ' === $ subPkg ->getType ()) {
83
- $ subOp = new Operation (true , $ op ->shouldSort ());
84
- $ subOp ->addPackage ($ subPkg ->getName (), $ constraint , $ package ['dev ' ]);
85
- $ result = $ this ->unpack ($ subOp , $ result , $ links );
90
+ foreach ($ requires as $ link ) {
91
+ if ('php ' === $ linkName = $ link ->getTarget ()) {
86
92
continue ;
87
93
}
88
94
89
- if ('* ' === $ constraint ) {
90
- if (null === $ versionSelector ) {
91
- $ pool = class_exists (RepositorySet::class) ? RepositorySet::class : Pool::class;
92
- $ pool = new $ pool ($ this ->composer ->getPackage ()->getMinimumStability (), $ this ->composer ->getPackage ()->getStabilityFlags ());
93
- $ pool ->addRepository (new CompositeRepository ($ this ->composer ->getRepositoryManager ()->getRepositories ()));
94
- $ versionSelector = new VersionSelector ($ pool );
95
+ $ constraint = $ link ->getPrettyConstraint ();
96
+ $ constraint = substr ($ this ->resolver ->parseVersion ($ linkName , $ constraint , true ), 1 ) ?: $ constraint ;
97
+
98
+ if ($ subPkg = $ localRepo ->findPackage ($ linkName , '* ' )) {
99
+ if ('symfony-pack ' === $ subPkg ->getType ()) {
100
+ $ subOp = new Operation (true , $ op ->shouldSort ());
101
+ $ subOp ->addPackage ($ subPkg ->getName (), $ constraint , $ dev );
102
+ $ result = $ this ->unpack ($ subOp , $ result , $ links , $ dev );
103
+ continue ;
95
104
}
96
105
97
- $ constraint = $ versionSelector ->findRecommendedRequireVersion ($ subPkg );
106
+ if ('* ' === $ constraint ) {
107
+ if (null === $ versionSelector ) {
108
+ $ pool = class_exists (RepositorySet::class) ? RepositorySet::class : Pool::class;
109
+ $ pool = new $ pool ($ this ->composer ->getPackage ()->getMinimumStability (), $ this ->composer ->getPackage ()->getStabilityFlags ());
110
+ $ pool ->addRepository (new CompositeRepository ($ this ->composer ->getRepositoryManager ()->getRepositories ()));
111
+ $ versionSelector = new VersionSelector ($ pool );
112
+ }
113
+
114
+ $ constraint = $ versionSelector ->findRecommendedRequireVersion ($ subPkg );
115
+ }
98
116
}
99
- }
100
117
101
- $ linkName = $ link ->getTarget ();
102
- $ linkType = $ package ['dev ' ] ? 'require-dev ' : 'require ' ;
103
- $ constraint = $ this ->versionParser ->parseConstraints ($ constraint );
118
+ $ linkType = $ dev ? 'require-dev ' : 'require ' ;
119
+ $ constraint = $ this ->versionParser ->parseConstraints ($ constraint );
104
120
105
- if (isset ($ links [$ linkName ])) {
106
- $ links [$ linkName ]['constraints ' ][] = $ constraint ;
107
- if ('require ' === $ linkType ) {
108
- $ links [$ linkName ]['type ' ] = 'require ' ;
121
+ if (isset ($ links [$ linkName ])) {
122
+ $ links [$ linkName ]['constraints ' ][] = $ constraint ;
123
+ if ('require ' === $ linkType ) {
124
+ $ links [$ linkName ]['type ' ] = 'require ' ;
125
+ }
126
+ } else {
127
+ $ links [$ linkName ] = [
128
+ 'type ' => $ linkType ,
129
+ 'name ' => $ linkName ,
130
+ 'constraints ' => [$ constraint ],
131
+ ];
109
132
}
110
- } else {
111
- $ links [$ linkName ] = [
112
- 'type ' => $ linkType ,
113
- 'name ' => $ linkName ,
114
- 'constraints ' => [$ constraint ],
115
- ];
116
133
}
117
134
}
118
135
}
0 commit comments