@@ -21,15 +21,14 @@ public function match($rawPathinfo)
2121 $ pathinfo = rawurldecode ($ rawPathinfo );
2222 $ trimmedPathinfo = rtrim ($ pathinfo , '/ ' );
2323 $ context = $ this ->context ;
24- $ request = $ this ->request ;
24+ $ request = $ this ->request ?: $ this -> createRequest ( $ pathinfo ) ;
2525 $ requestMethod = $ canonicalMethod = $ context ->getMethod ();
2626 $ scheme = $ context ->getScheme ();
2727
2828 if ('HEAD ' === $ requestMethod ) {
2929 $ canonicalMethod = 'GET ' ;
3030 }
3131
32-
3332 if (0 === strpos ($ pathinfo , '/a ' )) {
3433 // a_first
3534 if ('/a/11 ' === $ pathinfo ) {
@@ -57,32 +56,47 @@ public function match($rawPathinfo)
5756 // a_fourth
5857 if ('/a/44 ' === $ trimmedPathinfo ) {
5958 $ ret = array ('_route ' => 'a_fourth ' );
60- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
59+ if ('/ ' === substr ($ pathinfo , -1 )) {
60+ // no-op
61+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
62+ goto not_a_fourth;
63+ } else {
6164 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'a_fourth ' ));
6265 }
6366
6467 return $ ret ;
6568 }
69+ not_a_fourth:
6670
6771 // a_fifth
6872 if ('/a/55 ' === $ trimmedPathinfo ) {
6973 $ ret = array ('_route ' => 'a_fifth ' );
70- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
74+ if ('/ ' === substr ($ pathinfo , -1 )) {
75+ // no-op
76+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
77+ goto not_a_fifth;
78+ } else {
7179 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'a_fifth ' ));
7280 }
7381
7482 return $ ret ;
7583 }
84+ not_a_fifth:
7685
7786 // a_sixth
7887 if ('/a/66 ' === $ trimmedPathinfo ) {
7988 $ ret = array ('_route ' => 'a_sixth ' );
80- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
89+ if ('/ ' === substr ($ pathinfo , -1 )) {
90+ // no-op
91+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
92+ goto not_a_sixth;
93+ } else {
8194 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'a_sixth ' ));
8295 }
8396
8497 return $ ret ;
8598 }
99+ not_a_sixth:
86100
87101 }
88102
@@ -95,65 +109,95 @@ public function match($rawPathinfo)
95109 // nested_a
96110 if ('/nested/group/a ' === $ trimmedPathinfo ) {
97111 $ ret = array ('_route ' => 'nested_a ' );
98- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
112+ if ('/ ' === substr ($ pathinfo , -1 )) {
113+ // no-op
114+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
115+ goto not_nested_a;
116+ } else {
99117 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'nested_a ' ));
100118 }
101119
102120 return $ ret ;
103121 }
122+ not_nested_a:
104123
105124 // nested_b
106125 if ('/nested/group/b ' === $ trimmedPathinfo ) {
107126 $ ret = array ('_route ' => 'nested_b ' );
108- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
127+ if ('/ ' === substr ($ pathinfo , -1 )) {
128+ // no-op
129+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
130+ goto not_nested_b;
131+ } else {
109132 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'nested_b ' ));
110133 }
111134
112135 return $ ret ;
113136 }
137+ not_nested_b:
114138
115139 // nested_c
116140 if ('/nested/group/c ' === $ trimmedPathinfo ) {
117141 $ ret = array ('_route ' => 'nested_c ' );
118- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
142+ if ('/ ' === substr ($ pathinfo , -1 )) {
143+ // no-op
144+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
145+ goto not_nested_c;
146+ } else {
119147 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'nested_c ' ));
120148 }
121149
122150 return $ ret ;
123151 }
152+ not_nested_c:
124153
125154 }
126155
127156 elseif (0 === strpos ($ pathinfo , '/slashed/group ' )) {
128157 // slashed_a
129158 if ('/slashed/group ' === $ trimmedPathinfo ) {
130159 $ ret = array ('_route ' => 'slashed_a ' );
131- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
160+ if ('/ ' === substr ($ pathinfo , -1 )) {
161+ // no-op
162+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
163+ goto not_slashed_a;
164+ } else {
132165 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'slashed_a ' ));
133166 }
134167
135168 return $ ret ;
136169 }
170+ not_slashed_a:
137171
138172 // slashed_b
139173 if ('/slashed/group/b ' === $ trimmedPathinfo ) {
140174 $ ret = array ('_route ' => 'slashed_b ' );
141- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
175+ if ('/ ' === substr ($ pathinfo , -1 )) {
176+ // no-op
177+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
178+ goto not_slashed_b;
179+ } else {
142180 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'slashed_b ' ));
143181 }
144182
145183 return $ ret ;
146184 }
185+ not_slashed_b:
147186
148187 // slashed_c
149188 if ('/slashed/group/c ' === $ trimmedPathinfo ) {
150189 $ ret = array ('_route ' => 'slashed_c ' );
151- if (substr ($ pathinfo , -1 ) !== '/ ' ) {
190+ if ('/ ' === substr ($ pathinfo , -1 )) {
191+ // no-op
192+ } elseif (!in_array ($ this ->context ->getMethod (), array ('HEAD ' , 'GET ' ))) {
193+ goto not_slashed_c;
194+ } else {
152195 return array_replace ($ ret , $ this ->redirect ($ rawPathinfo .'/ ' , 'slashed_c ' ));
153196 }
154197
155198 return $ ret ;
156199 }
200+ not_slashed_c:
157201
158202 }
159203
0 commit comments