From def573f869c4319b695ea2d809ab1934142ead25 Mon Sep 17 00:00:00 2001 From: MGatner Date: Wed, 22 May 2019 15:55:00 -0400 Subject: [PATCH] Add CLI override for HTTPVerb CodeIgniter.php sets the request method on `request` or `clirequest` service, so RouteCollection needs to check the proper service to get the correct HTTPVerb to account for CLI, spoofing, and standard scenarios. See https://github.com/codeigniter4/CodeIgniter4/issues/2021 --- system/Router/RouteCollection.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 6654077f3858..66d5245d1f7a 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -234,8 +234,11 @@ class RouteCollection implements RouteCollectionInterface */ public function __construct(FileLocator $locator, $moduleConfig) { + // Load the correct request service + $request = (is_cli() && ! (ENVIRONMENT === 'testing')) ? Services::clirequest() : Services::request(); + // Get HTTP verb from current request (accounts for spoofing) - $this->HTTPVerb = Services::request()->getMethod(); + $this->HTTPVerb = $request->getMethod(); $this->fileLocator = $locator;