@@ -111,7 +111,7 @@ private function generateMatchMethod(): string
111
111
112
112
$ code = <<<EOF
113
113
{
114
- \$allow = \$allowSchemes = array() ;
114
+ \$allow = \$allowSchemes = [] ;
115
115
\$pathinfo = rawurldecode( \$pathinfo) ?: '/';
116
116
\$trimmedPathinfo = rtrim( \$pathinfo, '/') ?: '/';
117
117
\$context = \$this->context;
@@ -129,14 +129,14 @@ private function generateMatchMethod(): string
129
129
return <<<'EOF'
130
130
public function match($pathinfo)
131
131
{
132
- $allow = $allowSchemes = array() ;
132
+ $allow = $allowSchemes = [] ;
133
133
if ($ret = $this->doMatch($pathinfo, $allow, $allowSchemes)) {
134
134
return $ret;
135
135
}
136
136
if ($allow) {
137
137
throw new MethodNotAllowedException(array_keys($allow));
138
138
}
139
- if (!in_array($this->context->getMethod(), array( 'HEAD', 'GET') , true)) {
139
+ if (!in_array($this->context->getMethod(), [ 'HEAD', 'GET'] , true)) {
140
140
// no-op
141
141
} elseif ($allowSchemes) {
142
142
redirect_scheme:
@@ -162,10 +162,10 @@ public function match($pathinfo)
162
162
throw new ResourceNotFoundException();
163
163
}
164
164
165
- private function doMatch(string $pathinfo, array &$allow = array() , array &$allowSchemes = array() ): array
165
+ private function doMatch(string $pathinfo, array &$allow = [] , array &$allowSchemes = [] ): array
166
166
167
167
EOF
168
- .$ code ."\n return array() ; \n } " ;
168
+ .$ code ."\n return [] ; \n } " ;
169
169
}
170
170
171
171
return " public function match( \$pathinfo) \n" .$ code ."\n throw \$allow ? new MethodNotAllowedException(array_keys( \$allow)) : new ResourceNotFoundException(); \n } " ;
@@ -272,7 +272,7 @@ private function compileStaticRoutes(array $staticRoutes, bool $matchHost): stri
272
272
unset($ defaults ['_canonical_route ' ]);
273
273
}
274
274
$ default .= sprintf (
275
- "%s => array( %s, %s, %s, %s, %s) , \n" ,
275
+ "%s => [ %s, %s, %s, %s, %s] , \n" ,
276
276
self ::export ($ url ),
277
277
self ::export (['_route ' => $ name ] + $ defaults ),
278
278
self ::export (!$ route ->compile ()->getHostVariables () ? $ route ->getHost () : $ route ->compile ()->getHostRegex () ?: null ),
@@ -294,8 +294,8 @@ private function compileStaticRoutes(array $staticRoutes, bool $matchHost): stri
294
294
if ($ default ) {
295
295
$ code .= <<<EOF
296
296
default:
297
- \$routes = array(
298
- {$ this ->indent ($ default , 4 )} ) ;
297
+ \$routes = [
298
+ {$ this ->indent ($ default , 4 )} ] ;
299
299
300
300
if (!isset( \$routes[ \$trimmedPathinfo])) {
301
301
break;
@@ -437,8 +437,8 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
437
437
if ($ state ->default ) {
438
438
$ state ->switch .= <<<EOF
439
439
default:
440
- \$routes = array(
441
- {$ this ->indent ($ state ->default , 4 )} ) ;
440
+ \$routes = [
441
+ {$ this ->indent ($ state ->default , 4 )} ] ;
442
442
443
443
list( \$ret, \$vars, \$requiredMethods, \$requiredSchemes, \$hasTrailingSlash, \$hasTrailingVar) = \$routes[ \$m];
444
444
{$ this ->compileSwitchDefault (true , $ matchHost )}
@@ -450,8 +450,8 @@ private function compileDynamicRoutes(RouteCollection $collection, bool $matchHo
450
450
451
451
return <<<EOF
452
452
\$matchedPathinfo = {$ matchedPathinfo };
453
- \$regexList = array( {$ code }
454
- ) ;
453
+ \$regexList = [ {$ code }
454
+ ] ;
455
455
456
456
foreach ( \$regexList as \$offset => \$regex) {
457
457
while (preg_match( \$regex, \$matchedPathinfo, \$matches)) {
@@ -518,7 +518,7 @@ private function compileStaticPrefixCollection(StaticPrefixCollection $tree, \st
518
518
unset($ defaults ['_canonical_route ' ]);
519
519
}
520
520
$ state ->default .= sprintf (
521
- "%s => array( %s, %s, %s, %s, %s, %s) , \n" ,
521
+ "%s => [ %s, %s, %s, %s, %s, %s] , \n" ,
522
522
$ state ->mark ,
523
523
self ::export (['_route ' => $ name ] + $ defaults ),
524
524
self ::export ($ vars ),
@@ -551,7 +551,7 @@ private function compileSwitchDefault(bool $hasVars, bool $matchHost): string
551
551
$ code = <<<'EOF'
552
552
553
553
if ('GET' === $canonicalMethod && (!$requiredMethods || isset($requiredMethods['GET']))) {
554
- return $allow = $allowSchemes = array() ;
554
+ return $allow = $allowSchemes = [] ;
555
555
}
556
556
EOF;
557
557
} else {
@@ -699,7 +699,7 @@ private function compileRoute(Route $route, string $name, bool $checkHost, bool
699
699
$ code = sprintf ($ code , <<<'EOF'
700
700
701
701
if ('GET' === $canonicalMethod) {
702
- return $allow = $allowSchemes = array() ;
702
+ return $allow = $allowSchemes = [] ;
703
703
}
704
704
EOF
705
705
,
@@ -710,11 +710,11 @@ private function compileRoute(Route $route, string $name, bool $checkHost, bool
710
710
}
711
711
712
712
if ($ vars ) {
713
- $ code .= ' $matches = array( ' ;
713
+ $ code .= ' $matches = [ ' ;
714
714
foreach ($ vars as $ j => $ m ) {
715
715
$ code .= sprintf ('%s => $matches[%d] ?? null, ' , self ::export ($ m ), 1 + $ j );
716
716
}
717
- $ code = substr_replace ($ code , ") ; \n\n" , -2 );
717
+ $ code = substr_replace ($ code , "] ; \n\n" , -2 );
718
718
}
719
719
720
720
if ($ route ->getCondition ()) {
@@ -755,7 +755,7 @@ private function compileRoute(Route $route, string $name, bool $checkHost, bool
755
755
756
756
// optimize parameters array
757
757
if ($ matches || $ hostMatches ) {
758
- $ vars = ["array( '_route' => '$ name') " ];
758
+ $ vars = ["[ '_route' => '$ name'] " ];
759
759
if ($ matches || ($ hostMatches && !$ checkHost )) {
760
760
$ vars [] = '$matches ' ;
761
761
}
@@ -771,7 +771,7 @@ private function compileRoute(Route $route, string $name, bool $checkHost, bool
771
771
} elseif ($ defaults ) {
772
772
$ code .= sprintf (" \$ret = %s; \n" , self ::export (['_route ' => $ name ] + $ defaults ));
773
773
} else {
774
- $ code .= sprintf (" \$ret = array( '_route' => '%s') ; \n" , $ name );
774
+ $ code .= sprintf (" \$ret = [ '_route' => '%s'] ; \n" , $ name );
775
775
}
776
776
777
777
if ($ methods ) {
@@ -865,11 +865,11 @@ public static function export($value): string
865
865
return str_replace ("\n" , '\'."\n". \'' , var_export ($ value , true ));
866
866
}
867
867
if (!$ value ) {
868
- return 'array() ' ;
868
+ return '[] ' ;
869
869
}
870
870
871
871
$ i = 0 ;
872
- $ export = 'array( ' ;
872
+ $ export = '[ ' ;
873
873
874
874
foreach ($ value as $ k => $ v ) {
875
875
if ($ i === $ k ) {
@@ -885,6 +885,6 @@ public static function export($value): string
885
885
$ export .= self ::export ($ v ).', ' ;
886
886
}
887
887
888
- return substr_replace ($ export , ') ' , -2 );
888
+ return substr_replace ($ export , '] ' , -2 );
889
889
}
890
890
}
0 commit comments