@@ -1348,22 +1348,37 @@ public function setMethod($method)
1348
1348
*/
1349
1349
public function getMethod ()
1350
1350
{
1351
- if (null === $ this ->method ) {
1352
- $ this ->method = strtoupper ($ this ->server ->get ('REQUEST_METHOD ' , 'GET ' ));
1353
-
1354
- if ('POST ' === $ this ->method ) {
1355
- if ($ method = $ this ->headers ->get ('X-HTTP-METHOD-OVERRIDE ' )) {
1356
- $ this ->method = strtoupper ($ method );
1357
- } elseif (self ::$ httpMethodParameterOverride ) {
1358
- $ method = $ this ->request ->get ('_method ' , $ this ->query ->get ('_method ' , 'POST ' ));
1359
- if (\is_string ($ method )) {
1360
- $ this ->method = strtoupper ($ method );
1361
- }
1362
- }
1363
- }
1351
+ if (null !== $ this ->method ) {
1352
+ return $ this ->method ;
1353
+ }
1354
+
1355
+ $ this ->method = strtoupper ($ this ->server ->get ('REQUEST_METHOD ' , 'GET ' ));
1356
+
1357
+ if ('POST ' !== $ this ->method ) {
1358
+ return $ this ->method ;
1359
+ }
1360
+
1361
+ $ method = $ this ->headers ->get ('X-HTTP-METHOD-OVERRIDE ' );
1362
+
1363
+ if (!$ method && self ::$ httpMethodParameterOverride ) {
1364
+ $ method = $ this ->request ->get ('_method ' , $ this ->query ->get ('_method ' , 'POST ' ));
1365
+ }
1366
+
1367
+ if (!\is_string ($ method )) {
1368
+ return $ this ->method ;
1369
+ }
1370
+
1371
+ $ method = strtoupper ($ method );
1372
+
1373
+ if (\in_array ($ method , ['GET ' , 'HEAD ' , 'POST ' , 'PUT ' , 'DELETE ' , 'CONNECT ' , 'OPTIONS ' , 'PATCH ' , 'PURGE ' , 'TRACE ' ], true )) {
1374
+ return $ this ->method = $ method ;
1375
+ }
1376
+
1377
+ if (!preg_match ('/^[A-Z]++$/D ' , $ method )) {
1378
+ throw new SuspiciousOperationException (sprintf ('Invalid method override "%s". ' , $ method ));
1364
1379
}
1365
1380
1366
- return $ this ->method ;
1381
+ return $ this ->method = $ method ;
1367
1382
}
1368
1383
1369
1384
/**
0 commit comments