From 447bfb23ca16620ec6bd0eb74d3156ee1f1d525e Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Tue, 14 Jan 2025 17:26:48 +0700 Subject: [PATCH 1/2] refactor: replace handleRequest to filters for one call service --- system/CodeIgniter.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index fec178149bee..1016a9bc478d 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -175,7 +175,7 @@ public function __construct(App $config) $this->startTime = microtime(true); $this->config = $config; - $this->pageCache = Services::responsecache(); + $this->pageCache = service('responsecache'); } /** @@ -341,8 +341,12 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon $this->benchmark->stop('bootstrap'); $this->benchmark->start('required_before_filters'); - // Start up the filters - $filters = Services::filters(); + /** + * Start up the filters + * + * @var \CodeIgniter\Filters\Filters $filters + */ + $filters = service('filters'); // Run required before filters $possibleResponse = $this->runRequiredBeforeFilters($filters); @@ -351,7 +355,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon $this->response = $possibleResponse; } else { try { - $this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse); + $this->response = $this->handleRequest($routes, config(Cache::class), $filters); } catch (ResponsableInterface $e) { $this->outputBufferingEnd(); @@ -443,10 +447,8 @@ public function disableFilters(): void * * @throws PageNotFoundException * @throws RedirectException - * - * @deprecated $returnResponse is deprecated. */ - protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false) + protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, Filters $filters) { if ($this->request instanceof IncomingRequest && $this->request->getMethod() === 'CLI') { return $this->response->setStatusCode(405)->setBody('Method Not Allowed'); @@ -458,9 +460,6 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache $uri = $this->request->getPath(); if ($this->enableFilters) { - /** @var Filters $filters */ - $filters = service('filters'); - // If any filters were specified within the routes file, // we need to ensure it's active for the current request if ($routeFilters !== null) { @@ -516,8 +515,6 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache $this->gatherOutput($cacheConfig, $returned); if ($this->enableFilters) { - /** @var Filters $filters */ - $filters = service('filters'); $filters->setResponse($this->response); // Run "after" filters @@ -608,7 +605,7 @@ protected function startBenchmark() $this->startTime = microtime(true); } - $this->benchmark = Services::timer(); + $this->benchmark = service('timer'); $this->benchmark->start('total_execution', $this->startTime); $this->benchmark->start('bootstrap'); } @@ -901,7 +898,7 @@ protected function createController() assert(is_string($this->controller)); $class = new $this->controller(); - $class->initController($this->request, $this->response, Services::logger()); + $class->initController($this->request, $this->response, service('logger')); $this->benchmark->stop('controller_constructor'); From 2de7788f33b8f0e3ac098b0c513440743f635348 Mon Sep 17 00:00:00 2001 From: Denny Septian Panggabean Date: Tue, 14 Jan 2025 17:36:04 +0700 Subject: [PATCH 2/2] run cs-fix --- system/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 1016a9bc478d..af4b2bf6f021 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -344,7 +344,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon /** * Start up the filters * - * @var \CodeIgniter\Filters\Filters $filters + * @var Filters $filters */ $filters = service('filters'); // Run required before filters