Skip to content

Commit 091abaf

Browse files
authored
Merge pull request #8050 from kenjis/refactor-CodeIgniter
refactor: remove deprecated properties and methods in CodeIgniter class
2 parents 52fcf76 + dd952f4 commit 091abaf

File tree

4 files changed

+32
-68
lines changed

4 files changed

+32
-68
lines changed

phpstan-baseline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
];
184184
$ignoreErrors[] = [
185185
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
186-
'count' => 6,
186+
'count' => 5,
187187
'path' => __DIR__ . '/system/CodeIgniter.php',
188188
];
189189
$ignoreErrors[] = [

system/CodeIgniter.php

Lines changed: 18 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,6 @@ class CodeIgniter
135135
*/
136136
protected static $cacheTTL = 0;
137137

138-
/**
139-
* Request path to use.
140-
*
141-
* @var string
142-
*
143-
* @deprecated No longer used.
144-
*/
145-
protected $path;
146-
147-
/**
148-
* Should the Response instance "pretend"
149-
* to keep from setting headers/cookies/etc
150-
*
151-
* @var bool
152-
*
153-
* @deprecated No longer used.
154-
*/
155-
protected $useSafeOutput = false;
156-
157138
/**
158139
* Context
159140
* web: Invoked by HTTP request
@@ -171,7 +152,7 @@ class CodeIgniter
171152
/**
172153
* Whether to return Response object or send response.
173154
*
174-
* @deprecated No longer used.
155+
* @deprecated 4.4.0 No longer used.
175156
*/
176157
protected bool $returnResponse = false;
177158

@@ -336,6 +317,8 @@ private function configureKint(): void
336317
* tries to route the response, loads the controller and generally
337318
* makes all the pieces work together.
338319
*
320+
* @param bool $returnResponse Used for testing purposes only.
321+
*
339322
* @return ResponseInterface|void
340323
*/
341324
public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false)
@@ -355,9 +338,9 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
355338
$this->getRequestObject();
356339
$this->getResponseObject();
357340

358-
$this->spoofRequestMethod();
359-
360341
try {
342+
$this->forceSecureAccess();
343+
361344
$this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse);
362345
} catch (ResponsableInterface|DeprecatedRedirectException $e) {
363346
$this->outputBufferingEnd();
@@ -381,22 +364,6 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon
381364
$this->sendResponse();
382365
}
383366

384-
/**
385-
* Set our Response instance to "pretend" mode so that things like
386-
* cookies and headers are not actually sent, allowing PHP 7.2+ to
387-
* not complain when ini_set() function is used.
388-
*
389-
* @return $this
390-
*
391-
* @deprecated No longer used.
392-
*/
393-
public function useSafeOutput(bool $safe = true)
394-
{
395-
$this->useSafeOutput = $safe;
396-
397-
return $this;
398-
}
399-
400367
/**
401368
* Invoked via php-cli command?
402369
*/
@@ -433,8 +400,6 @@ public function disableFilters(): void
433400
*/
434401
protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false)
435402
{
436-
$this->forceSecureAccess();
437-
438403
if ($this->request instanceof IncomingRequest && strtolower($this->request->getMethod()) === 'cli') {
439404
return $this->response->setStatusCode(405)->setBody('Method Not Allowed');
440405
}
@@ -449,7 +414,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache
449414

450415
$routeFilters = $this->tryToRouteIt($routes);
451416

452-
$uri = $this->determinePath();
417+
$uri = $this->request->getPath();
453418

454419
if ($this->enableFilters) {
455420
// Start up the filters
@@ -621,6 +586,9 @@ protected function startBenchmark()
621586
* @param CLIRequest|IncomingRequest $request
622587
*
623588
* @return $this
589+
*
590+
* @internal Used for testing purposes only.
591+
* @testTag
624592
*/
625593
public function setRequest($request)
626594
{
@@ -637,6 +605,8 @@ public function setRequest($request)
637605
protected function getRequestObject()
638606
{
639607
if ($this->request instanceof Request) {
608+
$this->spoofRequestMethod();
609+
640610
return;
641611
}
642612

@@ -647,6 +617,8 @@ protected function getRequestObject()
647617
}
648618

649619
$this->request = Services::request();
620+
621+
$this->spoofRequestMethod();
650622
}
651623

652624
/**
@@ -808,14 +780,14 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
808780
// $routes is defined in Config/Routes.php
809781
$this->router = Services::router($routes, $this->request);
810782

811-
$path = $this->determinePath();
783+
$uri = $this->request->getPath();
812784

813785
$this->benchmark->stop('bootstrap');
814786
$this->benchmark->start('routing');
815787

816788
$this->outputBufferingStart();
817789

818-
$this->controller = $this->router->handle($path);
790+
$this->controller = $this->router->handle($uri);
819791
$this->method = $this->router->methodName();
820792

821793
// If a {locale} segment was matched in the final route,
@@ -834,31 +806,12 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null)
834806
* on the CLI/IncomingRequest path.
835807
*
836808
* @return string
837-
*/
838-
protected function determinePath()
839-
{
840-
if (! empty($this->path)) {
841-
return $this->path;
842-
}
843-
844-
return method_exists($this->request, 'getPath') ? $this->request->getPath() : $this->request->getUri()->getPath();
845-
}
846-
847-
/**
848-
* Allows the request path to be set from outside the class,
849-
* instead of relying on CLIRequest or IncomingRequest for the path.
850-
*
851-
* This is not used now.
852809
*
853-
* @return $this
854-
*
855-
* @deprecated No longer used.
810+
* @deprecated 4.5.0 No longer used.
856811
*/
857-
public function setPath(string $path)
812+
protected function determinePath()
858813
{
859-
$this->path = $path;
860-
861-
return $this;
814+
return $this->request->getPath();
862815
}
863816

864817
/**

tests/system/CodeIgniterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testRunEmptyDefaultRouteReturnResponse(): void
8787
$_SERVER['argv'] = ['index.php'];
8888
$_SERVER['argc'] = 1;
8989

90-
$response = $this->codeigniter->useSafeOutput(true)->run(null, true);
90+
$response = $this->codeigniter->run(null, true);
9191

9292
$this->assertStringContainsString('Welcome to CodeIgniter', $response->getBody());
9393
}
@@ -164,7 +164,7 @@ public function testRun404OverrideReturnResponse(): void
164164
$router = Services::router($routes, Services::incomingrequest());
165165
Services::injectMock('router', $router);
166166

167-
$response = $this->codeigniter->useSafeOutput(true)->run($routes, true);
167+
$response = $this->codeigniter->run($routes, true);
168168

169169
$this->assertStringContainsString('Oops', $response->getBody());
170170
}

user_guide_src/source/changelogs/v4.5.0.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ Model
109109
- ``Model::idValue()``
110110
- ``Model::classToArray()``
111111

112+
CodeIgniter
113+
-----------
114+
115+
- ``$path``
116+
- ``$useSafeOutput``
117+
- ``useSafeOutput()``
118+
- ``setPath()``
119+
112120
Enhancements
113121
************
114122

@@ -169,6 +177,9 @@ Changes
169177
Deprecations
170178
************
171179

180+
- **CodeIgniter:** The ``determinePath()`` method has been deprecated. No longer
181+
used.
182+
172183
Bugs Fixed
173184
**********
174185

0 commit comments

Comments
 (0)