Skip to content

Commit 447bfb2

Browse files
committed
refactor: replace handleRequest to filters for one call service
1 parent 17d6ade commit 447bfb2

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

system/CodeIgniter.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function __construct(App $config)
175175
$this->startTime = microtime(true);
176176
$this->config = $config;
177177

178-
$this->pageCache = Services::responsecache();
178+
$this->pageCache = service('responsecache');
179179
}
180180

181181
/**
@@ -341,8 +341,12 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
341341
$this->benchmark->stop('bootstrap');
342342

343343
$this->benchmark->start('required_before_filters');
344-
// Start up the filters
345-
$filters = Services::filters();
344+
/**
345+
* Start up the filters
346+
*
347+
* @var \CodeIgniter\Filters\Filters $filters
348+
*/
349+
$filters = service('filters');
346350
// Run required before filters
347351
$possibleResponse = $this->runRequiredBeforeFilters($filters);
348352

@@ -351,7 +355,7 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
351355
$this->response = $possibleResponse;
352356
} else {
353357
try {
354-
$this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
358+
$this->response = $this->handleRequest($routes, config(Cache::class), $filters);
355359
} catch (ResponsableInterface $e) {
356360
$this->outputBufferingEnd();
357361

@@ -443,10 +447,8 @@ public function disableFilters(): void
443447
*
444448
* @throws PageNotFoundException
445449
* @throws RedirectException
446-
*
447-
* @deprecated $returnResponse is deprecated.
448450
*/
449-
protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false)
451+
protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, Filters $filters)
450452
{
451453
if ($this->request instanceof IncomingRequest && $this->request->getMethod() === 'CLI') {
452454
return $this->response->setStatusCode(405)->setBody('Method Not Allowed');
@@ -458,9 +460,6 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
458460
$uri = $this->request->getPath();
459461

460462
if ($this->enableFilters) {
461-
/** @var Filters $filters */
462-
$filters = service('filters');
463-
464463
// If any filters were specified within the routes file,
465464
// we need to ensure it's active for the current request
466465
if ($routeFilters !== null) {
@@ -516,8 +515,6 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
516515
$this->gatherOutput($cacheConfig, $returned);
517516

518517
if ($this->enableFilters) {
519-
/** @var Filters $filters */
520-
$filters = service('filters');
521518
$filters->setResponse($this->response);
522519

523520
// Run "after" filters
@@ -608,7 +605,7 @@ protected function startBenchmark()
608605
$this->startTime = microtime(true);
609606
}
610607

611-
$this->benchmark = Services::timer();
608+
$this->benchmark = service('timer');
612609
$this->benchmark->start('total_execution', $this->startTime);
613610
$this->benchmark->start('bootstrap');
614611
}
@@ -901,7 +898,7 @@ protected function createController()
901898
assert(is_string($this->controller));
902899

903900
$class = new $this->controller();
904-
$class->initController($this->request, $this->response, Services::logger());
901+
$class->initController($this->request, $this->response, service('logger'));
905902

906903
$this->benchmark->stop('controller_constructor');
907904

0 commit comments

Comments
 (0)