From 42b75cbd957256f6c9a7731c26e360242fed9844 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:11:57 +0900 Subject: [PATCH 1/9] docs: add doc comments --- system/CodeIgniter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 1a1271a6a607..373818851030 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -336,6 +336,8 @@ private function configureKint(): void * tries to route the response, loads the controller and generally * makes all the pieces work together. * + * @param bool $returnResponse Used for testing purposes only. + * * @return ResponseInterface|void */ public function run(?RouteCollectionInterface $routes = null, bool $returnResponse = false) @@ -621,6 +623,9 @@ protected function startBenchmark() * @param CLIRequest|IncomingRequest $request * * @return $this + * + * @internal Used for testing purposes only. + * @testTag */ public function setRequest($request) { From 21e8f25f1f40a33dc1227fe68078b1b2c4b2f8ac Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:12:31 +0900 Subject: [PATCH 2/9] refactor: move forceSecureAccess() call --- system/CodeIgniter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 373818851030..c8ee089bbbde 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -360,6 +360,8 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon $this->spoofRequestMethod(); try { + $this->forceSecureAccess(); + $this->response = $this->handleRequest($routes, config(Cache::class), $returnResponse); } catch (ResponsableInterface|DeprecatedRedirectException $e) { $this->outputBufferingEnd(); @@ -435,8 +437,6 @@ public function disableFilters(): void */ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cacheConfig, bool $returnResponse = false) { - $this->forceSecureAccess(); - if ($this->request instanceof IncomingRequest && strtolower($this->request->getMethod()) === 'cli') { return $this->response->setStatusCode(405)->setBody('Method Not Allowed'); } From b20204af2f0cc2ceafea71d401bb1bfe9e3b1935 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:13:04 +0900 Subject: [PATCH 3/9] refactor: move spoofRequestMethod() into getRequestObject() --- system/CodeIgniter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index c8ee089bbbde..e9e1231df60b 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -357,8 +357,6 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon $this->getRequestObject(); $this->getResponseObject(); - $this->spoofRequestMethod(); - try { $this->forceSecureAccess(); @@ -642,6 +640,8 @@ public function setRequest($request) protected function getRequestObject() { if ($this->request instanceof Request) { + $this->spoofRequestMethod(); + return; } @@ -652,6 +652,8 @@ protected function getRequestObject() } $this->request = Services::request(); + + $this->spoofRequestMethod(); } /** From 21760f62b86ddc743a94db77a93186bbdd379acb Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:21:38 +0900 Subject: [PATCH 4/9] docs: add @deprecated version --- system/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index e9e1231df60b..efa62ba7cda2 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -171,7 +171,7 @@ class CodeIgniter /** * Whether to return Response object or send response. * - * @deprecated No longer used. + * @deprecated 4.4.0 No longer used. */ protected bool $returnResponse = false; From 4a636853e1707e458c53dc4323dc2866ac10ed42 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:22:10 +0900 Subject: [PATCH 5/9] refactor!: remove deprecated properties and methods --- system/CodeIgniter.php | 56 -------------------------------- tests/system/CodeIgniterTest.php | 4 +-- 2 files changed, 2 insertions(+), 58 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index efa62ba7cda2..b59e26fa33df 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -135,25 +135,6 @@ class CodeIgniter */ protected static $cacheTTL = 0; - /** - * Request path to use. - * - * @var string - * - * @deprecated No longer used. - */ - protected $path; - - /** - * Should the Response instance "pretend" - * to keep from setting headers/cookies/etc - * - * @var bool - * - * @deprecated No longer used. - */ - protected $useSafeOutput = false; - /** * Context * web: Invoked by HTTP request @@ -383,22 +364,6 @@ public function run(?RouteCollectionInterface $routes = null, bool $returnRespon $this->sendResponse(); } - /** - * Set our Response instance to "pretend" mode so that things like - * cookies and headers are not actually sent, allowing PHP 7.2+ to - * not complain when ini_set() function is used. - * - * @return $this - * - * @deprecated No longer used. - */ - public function useSafeOutput(bool $safe = true) - { - $this->useSafeOutput = $safe; - - return $this; - } - /** * Invoked via php-cli command? */ @@ -844,30 +809,9 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null) */ protected function determinePath() { - if (! empty($this->path)) { - return $this->path; - } - return method_exists($this->request, 'getPath') ? $this->request->getPath() : $this->request->getUri()->getPath(); } - /** - * Allows the request path to be set from outside the class, - * instead of relying on CLIRequest or IncomingRequest for the path. - * - * This is not used now. - * - * @return $this - * - * @deprecated No longer used. - */ - public function setPath(string $path) - { - $this->path = $path; - - return $this; - } - /** * Now that everything has been setup, this method attempts to run the * controller method and make the script go. If it's not able to, will diff --git a/tests/system/CodeIgniterTest.php b/tests/system/CodeIgniterTest.php index 54ea3d10445c..b7b5e092e609 100644 --- a/tests/system/CodeIgniterTest.php +++ b/tests/system/CodeIgniterTest.php @@ -87,7 +87,7 @@ public function testRunEmptyDefaultRouteReturnResponse(): void $_SERVER['argv'] = ['index.php']; $_SERVER['argc'] = 1; - $response = $this->codeigniter->useSafeOutput(true)->run(null, true); + $response = $this->codeigniter->run(null, true); $this->assertStringContainsString('Welcome to CodeIgniter', $response->getBody()); } @@ -164,7 +164,7 @@ public function testRun404OverrideReturnResponse(): void $router = Services::router($routes, Services::incomingrequest()); Services::injectMock('router', $router); - $response = $this->codeigniter->useSafeOutput(true)->run($routes, true); + $response = $this->codeigniter->run($routes, true); $this->assertStringContainsString('Oops', $response->getBody()); } From 3519bddd575d48509cdc16fd0823f0ef1843d780 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:31:35 +0900 Subject: [PATCH 6/9] refactor: remove unneeded method_exist() check --- system/CodeIgniter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index b59e26fa33df..01fb749d7158 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -809,7 +809,7 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null) */ protected function determinePath() { - return method_exists($this->request, 'getPath') ? $this->request->getPath() : $this->request->getUri()->getPath(); + return $this->request->getPath(); } /** From f2806b3a012940802c1cafb532f57a27456cd3c6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:36:22 +0900 Subject: [PATCH 7/9] refactor: make determinePath() deprecated --- system/CodeIgniter.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 01fb749d7158..c585715572fb 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -414,7 +414,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache $routeFilters = $this->tryToRouteIt($routes); - $uri = $this->determinePath(); + $uri = $this->request->getPath(); if ($this->enableFilters) { // Start up the filters @@ -780,14 +780,14 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null) // $routes is defined in Config/Routes.php $this->router = Services::router($routes, $this->request); - $path = $this->determinePath(); + $uri = $this->request->getPath(); $this->benchmark->stop('bootstrap'); $this->benchmark->start('routing'); $this->outputBufferingStart(); - $this->controller = $this->router->handle($path); + $this->controller = $this->router->handle($uri); $this->method = $this->router->methodName(); // If a {locale} segment was matched in the final route, @@ -806,6 +806,8 @@ protected function tryToRouteIt(?RouteCollectionInterface $routes = null) * on the CLI/IncomingRequest path. * * @return string + * + * @deprecated 4.5.0 No longer used. */ protected function determinePath() { From 94c423282ba131dcf550afd0114eb8a9343c6c2d Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:38:15 +0900 Subject: [PATCH 8/9] docs: add changelog --- user_guide_src/source/changelogs/v4.5.0.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index 1a1ac6fe901a..a936ec29d614 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -109,6 +109,14 @@ Model - ``Model::idValue()`` - ``Model::classToArray()`` +CodeIgniter +----------- + +- ``$path`` +- ``$useSafeOutput`` +- ``useSafeOutput()`` +- ``setPath()`` + Enhancements ************ @@ -169,6 +177,9 @@ Changes Deprecations ************ +- **CodeIgniter:** The ``determinePath()`` method has been deprecated. No longer + used. + Bugs Fixed ********** From dd952f4da10fa5903b921ae6fa06e257c715a61d Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 17 Oct 2023 09:43:48 +0900 Subject: [PATCH 9/9] chore: update phpstan-baseline --- phpstan-baseline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index dcfafb34160a..a88718ddfaba 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -183,7 +183,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 6, + 'count' => 5, 'path' => __DIR__ . '/system/CodeIgniter.php', ]; $ignoreErrors[] = [