@@ -111,15 +111,14 @@ private function injectGroup(Group $group, array &$tree, string $prefix = '', st
111111 $ namePrefix .= (string ) $ group ->getData ('namePrefix ' );
112112 $ items = $ group ->getData ('items ' );
113113 $ pattern = null ;
114- $ host = null ;
114+ $ hosts = [] ;
115115 foreach ($ items as $ item ) {
116116 if (!$ this ->isStaticRoute ($ item )) {
117117 $ item = $ item ->prependMiddleware (...$ group ->getData ('middlewareDefinitions ' ));
118118 }
119119
120- if ($ group ->getData ('host ' ) !== null && $ item ->getData ('host ' ) === null ) {
121- /** @psalm-suppress PossiblyNullArgument Checked group host on not null above. */
122- $ item = $ item ->host ($ group ->getData ('host ' ));
120+ if (!empty ($ group ->getData ('hosts ' )) && empty ($ item ->getData ('hosts ' ))) {
121+ $ item = $ item ->hosts (...$ group ->getData ('hosts ' ));
123122 }
124123
125124 if ($ item instanceof Group) {
@@ -150,7 +149,7 @@ private function injectGroup(Group $group, array &$tree, string $prefix = '', st
150149 }
151150
152151 if ($ group ->getData ('hasCorsMiddleware ' )) {
153- $ this ->processCors ($ group , $ host , $ pattern , $ modifiedItem , $ tree );
152+ $ this ->processCors ($ group , $ hosts , $ pattern , $ modifiedItem , $ tree );
154153 }
155154
156155 $ routeName = $ modifiedItem ->getData ('name ' );
@@ -167,21 +166,21 @@ private function injectGroup(Group $group, array &$tree, string $prefix = '', st
167166 */
168167 private function processCors (
169168 Group $ group ,
170- ? string &$ host ,
169+ array &$ hosts ,
171170 ?string &$ pattern ,
172171 Route &$ modifiedItem ,
173172 array &$ tree
174173 ): void {
175174 /** @var array|callable|string $middleware */
176175 $ middleware = $ group ->getData ('corsMiddleware ' );
177176 $ isNotDuplicate = !in_array (Method::OPTIONS , $ modifiedItem ->getData ('methods ' ), true )
178- && ($ pattern !== $ modifiedItem ->getData ('pattern ' ) || $ host !== $ modifiedItem ->getData ('host ' ));
177+ && ($ pattern !== $ modifiedItem ->getData ('pattern ' ) || $ hosts !== $ modifiedItem ->getData ('hosts ' ));
179178
180179 $ pattern = $ modifiedItem ->getData ('pattern ' );
181- $ host = $ modifiedItem ->getData ('host ' );
180+ $ hosts = $ modifiedItem ->getData ('hosts ' );
182181 $ optionsRoute = Route::options ($ pattern );
183- if ($ host !== null ) {
184- $ optionsRoute = $ optionsRoute ->host ( $ host );
182+ if (! empty ( $ hosts ) ) {
183+ $ optionsRoute = $ optionsRoute ->hosts (... $ hosts );
185184 }
186185 if ($ isNotDuplicate ) {
187186 $ optionsRoute = $ optionsRoute ->middleware ($ middleware );
0 commit comments