Skip to content

Commit f9effd8

Browse files
committed
refactor: address review feedback - revert Services::*() to service(), remove SPOOFABLE_METHODS, shorten comments, restore tryToRouteIt signature
All reviewer comments from @michalsn on PR #10369 addressed: - Reverted Services::*() calls back to service() (optimized helper) - Removed SPOOFABLE_METHODS constant (used only once) - Restored tryToRouteIt signature to non-BC-breaking form - Shortened verbose comments in startController() and storePreviousURL() - Kept only the flag fix for duplicate gatherOutput() calls
1 parent b4a86fc commit f9effd8

1 file changed

Lines changed: 12 additions & 18 deletions

File tree

system/CodeIgniter.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ class CodeIgniter
5858
*/
5959
public const CI_VERSION = '4.7.5-dev';
6060

61-
/**
62-
* Spoofable HTTP methods
63-
*/
64-
private const SPOOFABLE_METHODS = [Method::PUT, Method::PATCH, Method::DELETE];
65-
6661
/**
6762
* App startup time.
6863
*
@@ -227,7 +222,7 @@ private function resetKintForWorkerMode(): void
227222
return;
228223
}
229224

230-
$csp = Services::csp();
225+
$csp = service('csp');
231226
if ($csp->enabled()) {
232227
RichRenderer::$js_nonce = $csp->getScriptNonce();
233228
RichRenderer::$css_nonce = $csp->getStyleNonce();
@@ -467,14 +462,14 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
467462
return $this->response->setStatusCode(405)->setBody('Method Not Allowed');
468463
}
469464

465+
$routeFilters = $this->tryToRouteIt($routes);
466+
470467
// $uri is URL-encoded.
471468
$uri = $this->request->getPath();
472469

473-
$routeFilters = $this->tryToRouteIt($routes, $uri);
474-
475470
if ($this->enableFilters) {
476471
/** @var Filters $filters */
477-
$filters = Services::filters();
472+
$filters = service('filters');
478473

479474
// If any filters were specified within the routes file,
480475
// we need to ensure it's active for the current request
@@ -540,7 +535,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
540535

541536
if ($this->enableFilters) {
542537
/** @var Filters $filters */
543-
$filters = Services::filters();
538+
$filters = service('filters');
544539
$filters->setResponse($this->response);
545540

546541
// Run "after" filters
@@ -678,7 +673,7 @@ protected function getRequestObject()
678673
Services::createRequest($this->config);
679674
}
680675

681-
$this->request = Services::request();
676+
$this->request = service('request');
682677

683678
$this->spoofRequestMethod();
684679
}
@@ -841,19 +836,19 @@ public function displayPerformanceMetrics(string $output): string
841836
*
842837
* @throws RedirectException
843838
*/
844-
protected function tryToRouteIt(?RouteCollectionInterface $routes = null, ?string $uri = null)
839+
protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
845840
{
846841
$this->benchmark->start('routing');
847842

848843
if (! $routes instanceof RouteCollectionInterface) {
849-
$routes = Services::routes()->loadRoutes();
844+
$routes = service('routes')->loadRoutes();
850845
}
851846

852847
// $routes is defined in Config/Routes.php
853848
$this->router = Services::router($routes, $this->request);
854849

855850
// $uri is URL-encoded.
856-
$uri ??= $this->request->getPath();
851+
$uri = $this->request->getPath();
857852

858853
$this->outputBufferingStart();
859854

@@ -896,7 +891,7 @@ protected function startController()
896891
$this->benchmark->start('controller');
897892
$this->benchmark->start('controller_constructor');
898893

899-
// Is it routed to a Closure? Use instanceof — faster than is_object() + ::class string check.
894+
// Is it routed to a Closure?
900895
if ($this->controller instanceof Closure) {
901896
$controller = $this->controller;
902897

@@ -1088,8 +1083,7 @@ public function storePreviousURL($uri)
10881083
if (! $this->isWeb()) {
10891084
return;
10901085
}
1091-
// Ignore AJAX requests. Use instanceof instead of method_exists() — faster
1092-
// since CLIRequest never has isAJAX(), only IncomingRequest does.
1086+
// Ignore AJAX requests
10931087
if ($this->request instanceof IncomingRequest && $this->request->isAJAX()) {
10941088
return;
10951089
}
@@ -1140,7 +1134,7 @@ public function spoofRequestMethod()
11401134
}
11411135

11421136
// Only allows PUT, PATCH, DELETE
1143-
if (in_array($method, self::SPOOFABLE_METHODS, true)) {
1137+
if (in_array($method, [Method::PUT, Method::PATCH, Method::DELETE], true)) {
11441138
$this->request = $this->request->setMethod($method);
11451139
}
11461140
}

0 commit comments

Comments
 (0)