diff --git a/app/Config/Filters.php b/app/Config/Filters.php
index ac37b414c45c..6ebe0f3100ac 100644
--- a/app/Config/Filters.php
+++ b/app/Config/Filters.php
@@ -50,7 +50,7 @@ class Filters extends BaseConfig
* particular HTTP method (GET, POST, etc.).
*
* Example:
- * 'post' => ['foo', 'bar']
+ * 'POST' => ['foo', 'bar']
*
* If you use this, you should disable auto-routing because auto-routing
* permits any HTTP method to access a controller. Accessing the controller
diff --git a/app/Views/errors/html/error_exception.php b/app/Views/errors/html/error_exception.php
index 1c094d728872..d27d52fdc576 100644
--- a/app/Views/errors/html/error_exception.php
+++ b/app/Views/errors/html/error_exception.php
@@ -205,7 +205,7 @@
HTTP Method |
- = esc(strtoupper($request->getMethod())) ?> |
+ = esc($request->getMethod()) ?> |
IP Address |
diff --git a/phpstan-baseline.php b/phpstan-baseline.php
index e584035c7ba1..9c06aa1d95b4 100644
--- a/phpstan-baseline.php
+++ b/phpstan-baseline.php
@@ -1926,11 +1926,6 @@
'count' => 2,
'path' => __DIR__ . '/system/Filters/Filters.php',
];
-$ignoreErrors[] = [
- 'message' => '#^Expression on left side of \\?\\? is not nullable\\.$#',
- 'count' => 1,
- 'path' => __DIR__ . '/system/Filters/Filters.php',
-];
$ignoreErrors[] = [
'message' => '#^Only booleans are allowed in a negated boolean, array given\\.$#',
'count' => 1,
diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php
index 68cb5a9f5497..3e12e4e121b1 100644
--- a/system/CodeIgniter.php
+++ b/system/CodeIgniter.php
@@ -21,6 +21,7 @@
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\Exceptions\RedirectException;
use CodeIgniter\HTTP\IncomingRequest;
+use CodeIgniter\HTTP\Method;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\Request;
use CodeIgniter\HTTP\ResponsableInterface;
@@ -1027,7 +1028,7 @@ public function storePreviousURL($uri)
public function spoofRequestMethod()
{
// Only works with POSTED forms
- if (strtolower($this->request->getMethod()) !== 'post') {
+ if ($this->request->getMethod() !== Method::POST) {
return;
}
@@ -1038,7 +1039,7 @@ public function spoofRequestMethod()
}
// Only allows PUT, PATCH, DELETE
- if (in_array(strtoupper($method), ['PUT', 'PATCH', 'DELETE'], true)) {
+ if (in_array($method, [Method::PUT, Method::PATCH, Method::DELETE], true)) {
$this->request = $this->request->setMethod($method);
}
}
diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php
index 0f66f060f349..12c1930279e2 100644
--- a/system/Debug/Exceptions.php
+++ b/system/Debug/Exceptions.php
@@ -128,7 +128,7 @@ public function exceptionHandler(Throwable $exception)
if ($this->config->log === true && ! in_array($statusCode, $this->config->ignoreCodes, true)) {
$uri = $this->request->getPath() === '' ? '/' : $this->request->getPath();
- $routeInfo = '[Method: ' . strtoupper($this->request->getMethod()) . ', Route: ' . $uri . ']';
+ $routeInfo = '[Method: ' . $this->request->getMethod() . ', Route: ' . $uri . ']';
log_message('critical', "{message}\n{routeInfo}\nin {exFile} on line {exLine}.\n{trace}", [
'message' => $exception->getMessage(),
diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php
index 4a7a20632fd7..b2d54c5d52cc 100644
--- a/system/Debug/Toolbar.php
+++ b/system/Debug/Toolbar.php
@@ -79,7 +79,7 @@ public function run(float $startTime, float $totalTime, RequestInterface $reques
$data = [];
// Data items used within the view.
$data['url'] = current_url();
- $data['method'] = strtoupper($request->getMethod());
+ $data['method'] = $request->getMethod();
$data['isAJAX'] = $request->isAJAX();
$data['startTime'] = $startTime;
$data['totalTime'] = $totalTime * 1000;
diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php
index 8a28aeb0118e..9019c317aa1d 100644
--- a/system/Filters/Filters.php
+++ b/system/Filters/Filters.php
@@ -494,10 +494,28 @@ protected function processMethods()
return;
}
- // Request method won't be set for CLI-based requests
- $method = strtolower($this->request->getMethod()) ?? 'cli';
+ $method = $this->request->getMethod();
+
+ $found = false;
if (array_key_exists($method, $this->config->methods)) {
+ $found = true;
+ }
+ // Checks lowercase HTTP method for backward compatibility.
+ // @deprecated 4.5.0
+ // @TODO remove this in the future.
+ elseif (array_key_exists(strtolower($method), $this->config->methods)) {
+ @trigger_error(
+ 'Setting lowercase HTTP method key "' . strtolower($method) . '" is deprecated.'
+ . ' Use uppercase HTTP method like "' . strtoupper($method) . '".',
+ E_USER_DEPRECATED
+ );
+
+ $found = true;
+ $method = strtolower($method);
+ }
+
+ if ($found) {
if (config(Feature::class)->oldFilterOrder) {
$this->filters['before'] = array_merge($this->filters['before'], $this->config->methods[$method]);
} else {
diff --git a/system/HTTP/CLIRequest.php b/system/HTTP/CLIRequest.php
index 878e8a1d66c6..2b12694d86b9 100644
--- a/system/HTTP/CLIRequest.php
+++ b/system/HTTP/CLIRequest.php
@@ -56,7 +56,7 @@ class CLIRequest extends Request
*
* @var string
*/
- protected $method = 'cli';
+ protected $method = 'CLI';
/**
* Constructor
diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php
index c8b3b9fe9f92..9f5cd61ab275 100644
--- a/system/HTTP/CURLRequest.php
+++ b/system/HTTP/CURLRequest.php
@@ -112,7 +112,7 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response
throw HTTPException::forMissingCurl(); // @codeCoverageIgnore
}
- parent::__construct('GET', $uri);
+ parent::__construct(Method::GET, $uri);
$this->responseOrig = $response ?? new Response(config(App::class));
$this->baseURI = $uri->useRawQueryString();
@@ -130,7 +130,7 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response
* Sends an HTTP request to the specified $url. If this is a relative
* URL, it will be merged with $this->baseURI to form a complete URL.
*
- * @param string $method
+ * @param string $method HTTP method
*/
public function request($method, string $url, array $options = []): ResponseInterface
{
@@ -177,7 +177,7 @@ protected function resetOptions()
*/
public function get(string $url, array $options = []): ResponseInterface
{
- return $this->request('get', $url, $options);
+ return $this->request(Method::GET, $url, $options);
}
/**
@@ -185,7 +185,7 @@ public function get(string $url, array $options = []): ResponseInterface
*/
public function delete(string $url, array $options = []): ResponseInterface
{
- return $this->request('delete', $url, $options);
+ return $this->request('DELETE', $url, $options);
}
/**
@@ -193,7 +193,7 @@ public function delete(string $url, array $options = []): ResponseInterface
*/
public function head(string $url, array $options = []): ResponseInterface
{
- return $this->request('head', $url, $options);
+ return $this->request('HEAD', $url, $options);
}
/**
@@ -201,7 +201,7 @@ public function head(string $url, array $options = []): ResponseInterface
*/
public function options(string $url, array $options = []): ResponseInterface
{
- return $this->request('options', $url, $options);
+ return $this->request('OPTIONS', $url, $options);
}
/**
@@ -209,7 +209,7 @@ public function options(string $url, array $options = []): ResponseInterface
*/
public function patch(string $url, array $options = []): ResponseInterface
{
- return $this->request('patch', $url, $options);
+ return $this->request('PATCH', $url, $options);
}
/**
@@ -217,7 +217,7 @@ public function patch(string $url, array $options = []): ResponseInterface
*/
public function post(string $url, array $options = []): ResponseInterface
{
- return $this->request('post', $url, $options);
+ return $this->request(Method::POST, $url, $options);
}
/**
@@ -225,7 +225,7 @@ public function post(string $url, array $options = []): ResponseInterface
*/
public function put(string $url, array $options = []): ResponseInterface
{
- return $this->request('put', $url, $options);
+ return $this->request(Method::PUT, $url, $options);
}
/**
@@ -339,17 +339,6 @@ protected function prepareURL(string $url): string
);
}
- /**
- * Get the request method. Overrides the Request class' method
- * since users expect a different answer here.
- *
- * @param bool|false $upper Whether to return in upper or lower case.
- */
- public function getMethod(bool $upper = false): string
- {
- return ($upper) ? strtoupper($this->method) : strtolower($this->method);
- }
-
/**
* Fires the actual cURL request.
*
@@ -446,8 +435,6 @@ protected function applyRequestHeaders(array $curlOptions = []): array
*/
protected function applyMethod(string $method, array $curlOptions): array
{
- $method = strtoupper($method);
-
$this->method = $method;
$curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
@@ -458,7 +445,7 @@ protected function applyMethod(string $method, array $curlOptions): array
return $this->applyBody($curlOptions);
}
- if ($method === 'PUT' || $method === 'POST') {
+ if ($method === Method::PUT || $method === Method::POST) {
// See http://tools.ietf.org/html/rfc7230#section-3.3.2
if ($this->header('content-length') === null && ! isset($this->config['multipart'])) {
$this->setHeader('Content-Length', '0');
diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php
index e9365f79a85f..7641f42c4946 100755
--- a/system/HTTP/IncomingRequest.php
+++ b/system/HTTP/IncomingRequest.php
@@ -396,17 +396,18 @@ public function negotiate(string $type, array $supported, bool $strictMatch = fa
/**
* Checks this request type.
*
- * @param string $type HTTP verb or 'json' or 'ajax'
+ * @param string $type HTTP verb or 'json' or 'ajax'.
+ * HTTP verb should be case-sensitive, but this is case-insensitive.
* @phpstan-param string|'get'|'post'|'put'|'delete'|'head'|'patch'|'options'|'json'|'ajax' $type
*/
public function is(string $type): bool
{
$valueUpper = strtoupper($type);
- $httpMethods = ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH', 'OPTIONS'];
+ $httpMethods = Method::all();
if (in_array($valueUpper, $httpMethods, true)) {
- return strtoupper($this->getMethod()) === $valueUpper;
+ return $this->getMethod() === $valueUpper;
}
if ($valueUpper === 'JSON') {
diff --git a/system/HTTP/Method.php b/system/HTTP/Method.php
new file mode 100644
index 000000000000..7aae162b3cba
--- /dev/null
+++ b/system/HTTP/Method.php
@@ -0,0 +1,95 @@
+
+ *
+ * For the full copyright and license information, please view
+ * the LICENSE file that was distributed with this source code.
+ */
+
+namespace CodeIgniter\HTTP;
+
+/**
+ * HTTP Method List
+ */
+class Method
+{
+ /**
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT
+ */
+ public const CONNECT = 'CONNECT';
+
+ /**
+ * Idempotent
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE
+ */
+ public const DELETE = 'DELETE';
+
+ /**
+ * Safe, Idempotent, Cacheable
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET
+ */
+ public const GET = 'GET';
+
+ /**
+ * Safe, Idempotent, Cacheable
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD
+ */
+ public const HEAD = 'HEAD';
+
+ /**
+ * Safe, Idempotent
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
+ */
+ public const OPTIONS = 'OPTIONS';
+
+ /**
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
+ */
+ public const PATCH = 'PATCH';
+
+ /**
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST
+ */
+ public const POST = 'POST';
+
+ /**
+ * Idempotent
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT
+ */
+ public const PUT = 'PUT';
+
+ /**
+ * Safe, Idempotent
+ *
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/TRACE
+ */
+ public const TRACE = 'TRACE';
+
+ /**
+ * Returns all HTTP methods.
+ *
+ * @return list
+ */
+ public static function all(): array
+ {
+ return [
+ self::CONNECT,
+ self::DELETE,
+ self::GET,
+ self::HEAD,
+ self::OPTIONS,
+ self::PATCH,
+ self::POST,
+ self::PUT,
+ self::TRACE,
+ ];
+ }
+}
diff --git a/system/HTTP/OutgoingRequest.php b/system/HTTP/OutgoingRequest.php
index 698cde263bc1..b6f733f5ea3b 100644
--- a/system/HTTP/OutgoingRequest.php
+++ b/system/HTTP/OutgoingRequest.php
@@ -66,15 +66,13 @@ private function getHostFromUri(URI $uri): string
}
/**
- * Get the request method.
+ * Retrieves the HTTP method of the request.
*
- * @param bool $upper Whether to return in upper or lower case.
- *
- * @deprecated The $upper functionality will be removed and this will revert to its PSR-7 equivalent
+ * @return string Returns the request method (always uppercase)
*/
- public function getMethod(bool $upper = false): string
+ public function getMethod(): string
{
- return ($upper) ? strtoupper($this->method) : strtolower($this->method);
+ return $this->method;
}
/**
diff --git a/system/HTTP/OutgoingRequestInterface.php b/system/HTTP/OutgoingRequestInterface.php
index 3839b64fd8e1..b4a62dfde73f 100644
--- a/system/HTTP/OutgoingRequestInterface.php
+++ b/system/HTTP/OutgoingRequestInterface.php
@@ -21,14 +21,11 @@
interface OutgoingRequestInterface extends MessageInterface
{
/**
- * Get the request method.
- * An extension of PSR-7's getMethod to allow casing.
+ * Retrieves the HTTP method of the request.
*
- * @param bool $upper Whether to return in upper or lower case.
- *
- * @deprecated The $upper functionality will be removed and this will revert to its PSR-7 equivalent
+ * @return string Returns the request method.
*/
- public function getMethod(bool $upper = false): string;
+ public function getMethod(): string;
/**
* Return an instance with the provided HTTP method.
diff --git a/system/HTTP/Request.php b/system/HTTP/Request.php
index baf60c0305b6..1466175c7b8f 100644
--- a/system/HTTP/Request.php
+++ b/system/HTTP/Request.php
@@ -41,7 +41,7 @@ class Request extends OutgoingRequest implements RequestInterface
public function __construct($config = null) // @phpstan-ignore-line
{
if (empty($this->method)) {
- $this->method = $this->getServer('REQUEST_METHOD') ?? 'GET';
+ $this->method = $this->getServer('REQUEST_METHOD') ?? Method::GET;
}
if (empty($this->uri)) {
@@ -49,20 +49,6 @@ public function __construct($config = null) // @phpstan-ignore-line
}
}
- /**
- * Get the request method.
- *
- * @param bool $upper Whether to return in upper or lower case.
- *
- * @deprecated 4.0.5 The $upper functionality will be removed and this will revert to its PSR-7 equivalent
- *
- * @codeCoverageIgnore
- */
- public function getMethod(bool $upper = false): string
- {
- return ($upper) ? strtoupper($this->method) : strtolower($this->method);
- }
-
/**
* Sets the request method. Used when spoofing the request.
*
diff --git a/system/HTTP/ResponseTrait.php b/system/HTTP/ResponseTrait.php
index 9c4344e81c40..8d8cad504866 100644
--- a/system/HTTP/ResponseTrait.php
+++ b/system/HTTP/ResponseTrait.php
@@ -442,9 +442,9 @@ public function redirect(string $uri, string $method = 'auto', ?int $code = null
isset($_SERVER['SERVER_PROTOCOL'], $_SERVER['REQUEST_METHOD'])
&& $this->getProtocolVersion() >= 1.1
) {
- if ($_SERVER['REQUEST_METHOD'] === 'GET') {
+ if ($_SERVER['REQUEST_METHOD'] === Method::GET) {
$code = 302;
- } elseif (in_array($_SERVER['REQUEST_METHOD'], ['POST', 'PUT', 'DELETE'], true)) {
+ } elseif (in_array($_SERVER['REQUEST_METHOD'], [Method::POST, Method::PUT, Method::DELETE], true)) {
// reference: https://en.wikipedia.org/wiki/Post/Redirect/Get
$code = 303;
} else {
diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php
index 79b5e9de7d5d..05cb828976e7 100644
--- a/system/Router/RouteCollection.php
+++ b/system/Router/RouteCollection.php
@@ -1001,7 +1001,7 @@ public function presenter(string $name, ?array $options = null): RouteCollection
* Specifies a single route to match for multiple HTTP Verbs.
*
* Example:
- * $route->match( ['get', 'post'], 'users/(:num)', 'users/$1);
+ * $route->match( ['GET', 'POST'], 'users/(:num)', 'users/$1);
*
* @param array|Closure|string $to
*/
@@ -1012,6 +1012,18 @@ public function match(array $verbs = [], string $from = '', $to = '', ?array $op
}
foreach ($verbs as $verb) {
+ if ($verb === strtolower($verb)) {
+ @trigger_error(
+ 'Passing lowercase HTTP method "' . $verb . '" is deprecated.'
+ . ' Use uppercase HTTP method like "' . strtoupper($verb) . '".',
+ E_USER_DEPRECATED
+ );
+ }
+
+ /**
+ * @TODO We should use correct uppercase verb.
+ * @deprecated 4.5.0
+ */
$verb = strtolower($verb);
$this->{$verb}($from, $to, $options);
diff --git a/system/Security/Security.php b/system/Security/Security.php
index 4ba665639f36..9c28b82335b0 100644
--- a/system/Security/Security.php
+++ b/system/Security/Security.php
@@ -13,6 +13,7 @@
use CodeIgniter\Cookie\Cookie;
use CodeIgniter\HTTP\IncomingRequest;
+use CodeIgniter\HTTP\Method;
use CodeIgniter\HTTP\Request;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\I18n\Time;
@@ -280,8 +281,8 @@ public function getCSRFTokenName(): string
public function verify(RequestInterface $request)
{
// Protects POST, PUT, DELETE, PATCH
- $method = strtoupper($request->getMethod());
- $methodsToProtect = ['POST', 'PUT', 'DELETE', 'PATCH'];
+ $method = $request->getMethod();
+ $methodsToProtect = [Method::POST, Method::PUT, Method::DELETE, Method::PATCH];
if (! in_array($method, $methodsToProtect, true)) {
return $this;
}
diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php
index 6acef638f6b3..a254883865ad 100644
--- a/system/Test/FeatureTestTrait.php
+++ b/system/Test/FeatureTestTrait.php
@@ -36,7 +36,7 @@ trait FeatureTestTrait
*
* Example routes:
* [
- * ['get', 'home', 'Home::index']
+ * ['GET', 'home', 'Home::index'],
* ]
*
* @param array|null $routes Array to set routes
@@ -51,10 +51,24 @@ protected function withRoutes(?array $routes = null)
$collection->resetRoutes();
foreach ($routes as $route) {
+ if ($route[0] === strtolower($route[0])) {
+ @trigger_error(
+ 'Passing lowercase HTTP method "' . $route[0] . '" is deprecated.'
+ . ' Use uppercase HTTP method like "' . strtoupper($route[0]) . '".',
+ E_USER_DEPRECATED
+ );
+ }
+
+ /**
+ * @TODO For backward compatibility. Remove strtolower() in the future.
+ * @deprecated 4.5.0
+ */
+ $method = strtolower($route[0]);
+
if (isset($route[3])) {
- $collection->{$route[0]}($route[1], $route[2], $route[3]);
+ $collection->{$method}($route[1], $route[2], $route[3]);
} else {
- $collection->{$route[0]}($route[1], $route[2]);
+ $collection->{$method}($route[1], $route[2]);
}
}
}
diff --git a/system/Validation/Validation.php b/system/Validation/Validation.php
index 747ac66d9bc4..6313ea62c4fa 100644
--- a/system/Validation/Validation.php
+++ b/system/Validation/Validation.php
@@ -13,6 +13,7 @@
use Closure;
use CodeIgniter\HTTP\IncomingRequest;
+use CodeIgniter\HTTP\Method;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\Validation\Exceptions\ValidationException;
use CodeIgniter\View\RendererInterface;
@@ -501,7 +502,7 @@ public function withRequest(RequestInterface $request): ValidationInterface
return $this;
}
- if (in_array(strtolower($request->getMethod()), ['put', 'patch', 'delete'], true)
+ if (in_array($request->getMethod(), [Method::PUT, Method::PATCH, Method::DELETE], true)
&& strpos($request->getHeaderLine('Content-Type'), 'multipart/form-data') === false
) {
$this->data = $request->getRawInput();
diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php
index 505d1f5e5a7b..5d12863604f6 100644
--- a/tests/system/CodeIgniterTest.php
+++ b/tests/system/CodeIgniterTest.php
@@ -14,6 +14,7 @@
use CodeIgniter\Config\Services;
use CodeIgniter\Exceptions\ConfigException;
use CodeIgniter\Exceptions\PageNotFoundException;
+use CodeIgniter\HTTP\Method;
use CodeIgniter\HTTP\Response;
use CodeIgniter\Router\Exceptions\RedirectException;
use CodeIgniter\Router\RouteCollection;
@@ -721,7 +722,7 @@ public function testSpoofRequestMethodCanUsePUT(): void
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['REQUEST_METHOD'] = 'POST';
- $_POST['_method'] = 'PUT';
+ $_POST['_method'] = Method::PUT;
$routes = \Config\Services::routes();
$routes->setDefaultNamespace('App\Controllers');
@@ -733,7 +734,7 @@ public function testSpoofRequestMethodCanUsePUT(): void
$this->codeigniter->run();
ob_get_clean();
- $this->assertSame('put', Services::incomingrequest()->getMethod());
+ $this->assertSame(Method::PUT, Services::incomingrequest()->getMethod());
}
public function testSpoofRequestMethodCannotUseGET(): void
@@ -758,7 +759,7 @@ public function testSpoofRequestMethodCannotUseGET(): void
$this->codeigniter->run();
ob_get_clean();
- $this->assertSame('post', Services::incomingrequest()->getMethod());
+ $this->assertSame('POST', Services::incomingrequest()->getMethod());
}
/**
diff --git a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php
index c59c9b9aee8e..23ecb5c97f0b 100644
--- a/tests/system/Commands/Utilities/Routes/FilterFinderTest.php
+++ b/tests/system/Commands/Utilities/Routes/FilterFinderTest.php
@@ -87,7 +87,7 @@ private function createFilters(array $config = []): Filters
],
],
'methods' => [
- 'get' => [],
+ 'GET' => [],
],
'filters' => [
'honeypot' => ['before' => ['form/*', 'survey/*']],
@@ -215,7 +215,7 @@ public function testFilterOrder()
],
],
'methods' => [
- 'get' => ['method1', 'method2'],
+ 'GET' => ['method1', 'method2'],
],
'filters' => [
'filter1' => ['before' => '*', 'after' => '*'],
@@ -280,7 +280,7 @@ public function testFilterOrderWithOldFilterOrder()
],
],
'methods' => [
- 'get' => ['method1', 'method2'],
+ 'GET' => ['method1', 'method2'],
],
'filters' => [
'filter1' => ['before' => '*', 'after' => '*'],
diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php
index 7faf127f4647..f2412b289aa7 100644
--- a/tests/system/Filters/FiltersTest.php
+++ b/tests/system/Filters/FiltersTest.php
@@ -89,7 +89,7 @@ public function testProcessMethodDetectsCLI(): void
'aliases' => ['foo' => ''],
'globals' => [],
'methods' => [
- 'cli' => ['foo'],
+ 'CLI' => ['foo'],
],
];
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
@@ -113,7 +113,7 @@ public function testProcessMethodDetectsGetRequests(): void
'aliases' => ['foo' => ''],
'globals' => [],
'methods' => [
- 'get' => ['foo'],
+ 'GET' => ['foo'],
],
];
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
@@ -137,8 +137,8 @@ public function testProcessMethodRespectsMethod(): void
],
'globals' => [],
'methods' => [
- 'post' => ['foo'],
- 'get' => ['bar'],
+ 'POST' => ['foo'],
+ 'GET' => ['bar'],
],
];
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
@@ -162,8 +162,8 @@ public function testProcessMethodIgnoresMethod(): void
],
'globals' => [],
'methods' => [
- 'post' => ['foo'],
- 'get' => ['bar'],
+ 'POST' => ['foo'],
+ 'GET' => ['bar'],
],
];
$filtersConfig = $this->createConfigFromArray(FiltersConfig::class, $config);
@@ -348,8 +348,8 @@ public function testProcessMethodProcessesCombined(): void
],
],
'methods' => [
- 'post' => ['foo'],
- 'get' => ['bar'],
+ 'POST' => ['foo'],
+ 'GET' => ['bar'],
],
'filters' => [
'foof' => [
@@ -391,7 +391,7 @@ public function testProcessMethodProcessesCombinedAfterForToolbar(): void
],
],
'methods' => [
- 'get' => ['bar'],
+ 'GET' => ['bar'],
],
'filters' => [
'foof' => [
diff --git a/tests/system/HTTP/CLIRequestTest.php b/tests/system/HTTP/CLIRequestTest.php
index e15f0fca4f87..3c6293131d70 100644
--- a/tests/system/HTTP/CLIRequestTest.php
+++ b/tests/system/HTTP/CLIRequestTest.php
@@ -525,8 +525,7 @@ public function testGetIPAddressDefault(): void
public function testMethodReturnsRightStuff(): void
{
// Defaults method to CLI now.
- $this->assertSame('cli', $this->request->getMethod());
- $this->assertSame('CLI', $this->request->getMethod(true));
+ $this->assertSame('CLI', $this->request->getMethod());
}
public function testMethodIsCliReturnsAlwaysTrue(): void
diff --git a/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php b/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php
index d8e96424dae5..c9710616e2d2 100644
--- a/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php
+++ b/tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php
@@ -103,7 +103,7 @@ public function testGetSetsCorrectMethod(): void
{
$this->request->get('http://example.com');
- $this->assertSame('get', $this->request->getMethod());
+ $this->assertSame('GET', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -115,7 +115,7 @@ public function testDeleteSetsCorrectMethod(): void
{
$this->request->delete('http://example.com');
- $this->assertSame('delete', $this->request->getMethod());
+ $this->assertSame('DELETE', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -127,7 +127,7 @@ public function testHeadSetsCorrectMethod(): void
{
$this->request->head('http://example.com');
- $this->assertSame('head', $this->request->getMethod());
+ $this->assertSame('HEAD', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -139,7 +139,7 @@ public function testOptionsSetsCorrectMethod(): void
{
$this->request->options('http://example.com');
- $this->assertSame('options', $this->request->getMethod());
+ $this->assertSame('OPTIONS', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -281,7 +281,7 @@ public function testPatchSetsCorrectMethod(): void
{
$this->request->patch('http://example.com');
- $this->assertSame('patch', $this->request->getMethod());
+ $this->assertSame('PATCH', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -293,7 +293,7 @@ public function testPostSetsCorrectMethod(): void
{
$this->request->post('http://example.com');
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -305,7 +305,7 @@ public function testPutSetsCorrectMethod(): void
{
$this->request->put('http://example.com');
- $this->assertSame('put', $this->request->getMethod());
+ $this->assertSame('PUT', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -322,19 +322,19 @@ public function testCustomMethodSetsCorrectMethod(): void
$options = $this->request->curl_options;
$this->assertArrayHasKey(CURLOPT_CUSTOMREQUEST, $options);
- $this->assertSame('CUSTOM', $options[CURLOPT_CUSTOMREQUEST]);
+ $this->assertSame('custom', $options[CURLOPT_CUSTOMREQUEST]);
}
public function testRequestMethodGetsSanitized(): void
{
$this->request->request('', 'http://example.com');
- $this->assertSame('custom', $this->request->getMethod());
+ $this->assertSame('Custom', $this->request->getMethod());
$options = $this->request->curl_options;
$this->assertArrayHasKey(CURLOPT_CUSTOMREQUEST, $options);
- $this->assertSame('CUSTOM', $options[CURLOPT_CUSTOMREQUEST]);
+ $this->assertSame('Custom', $options[CURLOPT_CUSTOMREQUEST]);
}
public function testRequestSetsBasicCurlOptions(): void
@@ -951,7 +951,7 @@ public function testPostFormEncoded(): void
'form_params' => $params,
]);
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -974,7 +974,7 @@ public function testPostFormMultipart(): void
'multipart' => $params,
]);
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -1022,7 +1022,7 @@ public function testJSONData(): void
'json' => $params,
]);
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$expected = json_encode($params);
$this->assertSame(
diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php
index 186284da6ba6..2ca18aa87282 100644
--- a/tests/system/HTTP/CURLRequestTest.php
+++ b/tests/system/HTTP/CURLRequestTest.php
@@ -103,7 +103,7 @@ public function testGetSetsCorrectMethod(): void
{
$this->request->get('http://example.com');
- $this->assertSame('get', $this->request->getMethod());
+ $this->assertSame('GET', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -115,7 +115,7 @@ public function testDeleteSetsCorrectMethod(): void
{
$this->request->delete('http://example.com');
- $this->assertSame('delete', $this->request->getMethod());
+ $this->assertSame('DELETE', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -127,7 +127,7 @@ public function testHeadSetsCorrectMethod(): void
{
$this->request->head('http://example.com');
- $this->assertSame('head', $this->request->getMethod());
+ $this->assertSame('HEAD', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -139,7 +139,7 @@ public function testOptionsSetsCorrectMethod(): void
{
$this->request->options('http://example.com');
- $this->assertSame('options', $this->request->getMethod());
+ $this->assertSame('OPTIONS', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -264,7 +264,7 @@ public function testPatchSetsCorrectMethod(): void
{
$this->request->patch('http://example.com');
- $this->assertSame('patch', $this->request->getMethod());
+ $this->assertSame('PATCH', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -276,7 +276,7 @@ public function testPostSetsCorrectMethod(): void
{
$this->request->post('http://example.com');
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -288,7 +288,7 @@ public function testPutSetsCorrectMethod(): void
{
$this->request->put('http://example.com');
- $this->assertSame('put', $this->request->getMethod());
+ $this->assertSame('PUT', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -305,19 +305,19 @@ public function testCustomMethodSetsCorrectMethod(): void
$options = $this->request->curl_options;
$this->assertArrayHasKey(CURLOPT_CUSTOMREQUEST, $options);
- $this->assertSame('CUSTOM', $options[CURLOPT_CUSTOMREQUEST]);
+ $this->assertSame('custom', $options[CURLOPT_CUSTOMREQUEST]);
}
public function testRequestMethodGetsSanitized(): void
{
$this->request->request('', 'http://example.com');
- $this->assertSame('custom', $this->request->getMethod());
+ $this->assertSame('Custom', $this->request->getMethod());
$options = $this->request->curl_options;
$this->assertArrayHasKey(CURLOPT_CUSTOMREQUEST, $options);
- $this->assertSame('CUSTOM', $options[CURLOPT_CUSTOMREQUEST]);
+ $this->assertSame('Custom', $options[CURLOPT_CUSTOMREQUEST]);
}
public function testRequestSetsBasicCurlOptions(): void
@@ -934,7 +934,7 @@ public function testPostFormEncoded(): void
'form_params' => $params,
]);
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -957,7 +957,7 @@ public function testPostFormMultipart(): void
'multipart' => $params,
]);
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$options = $this->request->curl_options;
@@ -1005,7 +1005,7 @@ public function testJSONData(): void
'json' => $params,
]);
- $this->assertSame('post', $this->request->getMethod());
+ $this->assertSame('POST', $this->request->getMethod());
$expected = json_encode($params);
$this->assertSame($expected, $this->request->getBody());
diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php
index b8d0680a19ae..dc537093632e 100644
--- a/tests/system/HTTP/IncomingRequestTest.php
+++ b/tests/system/HTTP/IncomingRequestTest.php
@@ -840,7 +840,7 @@ public function testGetFile(): void
public function testSpoofing(): void
{
$this->request->setMethod('WINK');
- $this->assertSame('wink', $this->request->getMethod());
+ $this->assertSame('WINK', $this->request->getMethod());
}
/**
diff --git a/tests/system/HTTP/OutgoingRequestTest.php b/tests/system/HTTP/OutgoingRequestTest.php
index 51b2bab6a3fe..d857297d49ef 100644
--- a/tests/system/HTTP/OutgoingRequestTest.php
+++ b/tests/system/HTTP/OutgoingRequestTest.php
@@ -44,8 +44,8 @@ public function testWithMethod(): void
$newRequest = $request->withMethod('POST');
- $this->assertSame('GET', strtoupper($request->getMethod()));
- $this->assertSame('POST', strtoupper($newRequest->getMethod()));
+ $this->assertSame('GET', $request->getMethod());
+ $this->assertSame('POST', $newRequest->getMethod());
}
public function testWithUri(): void
diff --git a/tests/system/HTTP/RequestTest.php b/tests/system/HTTP/RequestTest.php
index be20b4ff8f5b..269156fc1982 100644
--- a/tests/system/HTTP/RequestTest.php
+++ b/tests/system/HTTP/RequestTest.php
@@ -639,7 +639,6 @@ public function testGetIPAddressThruProxyOutofSubnet(): void
public function testMethodReturnsRightStuff(): void
{
// Defaults method to GET now.
- $this->assertSame('get', $this->request->getMethod());
- $this->assertSame('GET', $this->request->getMethod(true));
+ $this->assertSame('GET', $this->request->getMethod());
}
}
diff --git a/tests/system/Helpers/URLHelper/MiscUrlTest.php b/tests/system/Helpers/URLHelper/MiscUrlTest.php
index 04da4f7352fe..62a86b675fad 100644
--- a/tests/system/Helpers/URLHelper/MiscUrlTest.php
+++ b/tests/system/Helpers/URLHelper/MiscUrlTest.php
@@ -966,7 +966,7 @@ public function testUrlToMissingArgument(): void
$routes = Services::routes();
$routes->group('(:alpha)', static function ($routes): void {
- $routes->match(['get'], 'login', 'Common\LoginController::loginView', ['as' => 'loginURL']);
+ $routes->match(['GET'], 'login', 'Common\LoginController::loginView', ['as' => 'loginURL']);
});
url_to('loginURL');
diff --git a/tests/system/HomeTest.php b/tests/system/HomeTest.php
index d7c132e9736d..915e5992b45e 100644
--- a/tests/system/HomeTest.php
+++ b/tests/system/HomeTest.php
@@ -28,7 +28,7 @@ public function testPageLoadsSuccessfully(): void
{
$this->withRoutes([
[
- 'get',
+ 'GET',
'home',
'\App\Controllers\Home::index',
],
diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php
index 985326dcf66d..06ab63f3e151 100644
--- a/tests/system/Router/RouteCollectionTest.php
+++ b/tests/system/Router/RouteCollectionTest.php
@@ -15,6 +15,7 @@
use CodeIgniter\Config\Services;
use CodeIgniter\controller;
use CodeIgniter\Exceptions\PageNotFoundException;
+use CodeIgniter\HTTP\Method;
use CodeIgniter\Test\CIUnitTestCase;
use Config\Modules;
use Config\Routing;
@@ -144,11 +145,11 @@ public function testAddIgnoresDefaultNamespaceWhenExists(): void
public function testAddWorksWithCurrentHTTPMethods(): void
{
- Services::request()->setMethod('get');
+ Services::request()->setMethod(Method::GET);
$routes = $this->getCollector();
- $routes->match(['get'], 'home', 'controller');
+ $routes->match(['GET'], 'home', 'controller');
$expects = [
'home' => '\controller',
@@ -176,11 +177,11 @@ public function testAddWithLeadingSlash(): void
public function testMatchIgnoresInvalidHTTPMethods(): void
{
- Services::request()->setMethod('get');
+ Services::request()->setMethod(Method::GET);
$routes = $this->getCollector();
- $routes->match(['put'], 'home', 'controller');
+ $routes->match(['PUT'], 'home', 'controller');
$routes = $routes->getRoutes();
@@ -189,7 +190,7 @@ public function testMatchIgnoresInvalidHTTPMethods(): void
public function testAddWorksWithArrayOFHTTPMethods(): void
{
- Services::request()->setMethod('post');
+ Services::request()->setMethod(Method::POST);
$routes = $this->getCollector();
@@ -696,7 +697,7 @@ public function testPresenterScaffoldsCorrectly(): void
public function testResourcesWithCustomController(): void
{
- Services::request()->setMethod('get');
+ Services::request()->setMethod(Method::GET);
$routes = $this->getCollector();
$routes->resource('photos', ['controller' => '