Skip to content

Commit b496f46

Browse files
authored
Merge pull request #7670 from kenjis/fix-Services-exceptions
fix: remove instantiation of Response in `Services::exceptions()`
2 parents fdd935d + 1b09623 commit b496f46

File tree

6 files changed

+24
-29
lines changed

6 files changed

+24
-29
lines changed

system/Config/BaseService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
* @method static CURLRequest curlrequest($options = [], ResponseInterface $response = null, App $config = null, $getShared = true)
102102
* @method static Email email($config = null, $getShared = true)
103103
* @method static EncrypterInterface encrypter(Encryption $config = null, $getShared = false)
104-
* @method static Exceptions exceptions(ConfigExceptions $config = null, IncomingRequest $request = null, ResponseInterface $response = null, $getShared = true)
104+
* @method static Exceptions exceptions(ConfigExceptions $config = null, $getShared = true)
105105
* @method static Filters filters(ConfigFilters $config = null, $getShared = true)
106106
* @method static Format format(ConfigFormat $config = null, $getShared = true)
107107
* @method static Honeypot honeypot(ConfigHoneyPot $config = null, $getShared = true)

system/Config/Services.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,18 @@ public static function encrypter(?EncryptionConfig $config = null, $getShared =
257257
* - register_shutdown_function
258258
*
259259
* @return Exceptions
260-
*
261-
* @deprecated The parameter $request and $response are deprecated.
262260
*/
263261
public static function exceptions(
264262
?ExceptionsConfig $config = null,
265-
?IncomingRequest $request = null,
266-
?ResponseInterface $response = null,
267263
bool $getShared = true
268264
) {
269265
if ($getShared) {
270-
return static::getSharedInstance('exceptions', $config, $request, $response);
266+
return static::getSharedInstance('exceptions', $config);
271267
}
272268

273269
$config ??= config(ExceptionsConfig::class);
274270

275-
// @TODO remove instantiation of Response in the future.
276-
$response ??= AppServices::response();
277-
278-
return new Exceptions($config, $request, $response);
271+
return new Exceptions($config);
279272
}
280273

281274
/**

system/Debug/Exceptions.php

+8-13
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Exceptions
3737
*
3838
* @var int
3939
*
40-
* @deprecated No longer used. Moved to BaseExceptionHandler.
40+
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
4141
*/
4242
public $ob_level;
4343

@@ -47,7 +47,7 @@ class Exceptions
4747
*
4848
* @var string
4949
*
50-
* @deprecated No longer used. Moved to BaseExceptionHandler.
50+
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
5151
*/
5252
protected $viewPath;
5353

@@ -74,12 +74,7 @@ class Exceptions
7474

7575
private ?Throwable $exceptionCaughtByExceptionHandler = null;
7676

77-
/**
78-
* @param RequestInterface|null $request
79-
*
80-
* @deprecated The parameter $request and $response are deprecated. No longer used.
81-
*/
82-
public function __construct(ExceptionsConfig $config, $request, ResponseInterface $response) /** @phpstan-ignore-line */
77+
public function __construct(ExceptionsConfig $config)
8378
{
8479
// For backward compatibility
8580
$this->ob_level = ob_get_level();
@@ -240,7 +235,7 @@ public function shutdownHandler()
240235
*
241236
* @return string The path and filename of the view file to use
242237
*
243-
* @deprecated No longer used. Moved to ExceptionHandler.
238+
* @deprecated 4.4.0 No longer used. Moved to ExceptionHandler.
244239
*/
245240
protected function determineView(Throwable $exception, string $templatePath): string
246241
{
@@ -268,7 +263,7 @@ protected function determineView(Throwable $exception, string $templatePath): st
268263
/**
269264
* Given an exception and status code will display the error to the client.
270265
*
271-
* @deprecated No longer used. Moved to BaseExceptionHandler.
266+
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
272267
*/
273268
protected function render(Throwable $exception, int $statusCode)
274269
{
@@ -310,7 +305,7 @@ protected function render(Throwable $exception, int $statusCode)
310305
/**
311306
* Gathers the variables that will be made available to the view.
312307
*
313-
* @deprecated No longer used. Moved to BaseExceptionHandler.
308+
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
314309
*/
315310
protected function collectVars(Throwable $exception, int $statusCode): array
316311
{
@@ -471,7 +466,7 @@ public static function cleanPath(string $file): string
471466
* Describes memory usage in real-world units. Intended for use
472467
* with memory_get_usage, etc.
473468
*
474-
* @deprecated No longer used. Moved to BaseExceptionHandler.
469+
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
475470
*/
476471
public static function describeMemory(int $bytes): string
477472
{
@@ -491,7 +486,7 @@ public static function describeMemory(int $bytes): string
491486
*
492487
* @return bool|string
493488
*
494-
* @deprecated No longer used. Moved to BaseExceptionHandler.
489+
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
495490
*/
496491
public static function highlightFile(string $file, int $lineNumber, int $lines = 15)
497492
{

tests/system/Config/ServicesTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ public function testNewUnsharedEmailWithNonEmptyConfig(): void
127127

128128
public function testNewExceptions(): void
129129
{
130-
$actual = Services::exceptions(new Exceptions(), Services::request(), Services::response());
130+
$actual = Services::exceptions(new Exceptions());
131131
$this->assertInstanceOf(\CodeIgniter\Debug\Exceptions::class, $actual);
132132
}
133133

134134
public function testNewExceptionsWithNullConfig(): void
135135
{
136-
$actual = Services::exceptions(null, null, null, false);
136+
$actual = Services::exceptions(null, false);
137137
$this->assertInstanceOf(\CodeIgniter\Debug\Exceptions::class, $actual);
138138
}
139139

tests/system/Debug/ExceptionsTest.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use CodeIgniter\Test\CIUnitTestCase;
2020
use CodeIgniter\Test\ReflectionHelper;
2121
use Config\Exceptions as ExceptionsConfig;
22-
use Config\Services;
2322
use ErrorException;
2423
use RuntimeException;
2524

@@ -52,7 +51,7 @@ protected function setUp(): void
5251
{
5352
parent::setUp();
5453

55-
$this->exception = new Exceptions(new ExceptionsConfig(), Services::request(), Services::response());
54+
$this->exception = new Exceptions(new ExceptionsConfig());
5655
}
5756

5857
/**
@@ -65,7 +64,7 @@ public function testDeprecationsOnPhp81DoNotThrow(): void
6564
$config->logDeprecations = true;
6665
$config->deprecationLogLevel = 'error';
6766

68-
$this->exception = new Exceptions($config, Services::request(), Services::response());
67+
$this->exception = new Exceptions($config);
6968
$this->exception->initialize();
7069

7170
// this is only needed for IDEs not to complain that strlen does not accept explicit null
@@ -89,7 +88,7 @@ public function testSuppressedDeprecationsAreLogged(): void
8988
$config->logDeprecations = true;
9089
$config->deprecationLogLevel = 'error';
9190

92-
$this->exception = new Exceptions($config, Services::request(), Services::response());
91+
$this->exception = new Exceptions($config);
9392
$this->exception->initialize();
9493

9594
@trigger_error('Hello! I am a deprecation!', E_USER_DEPRECATED);

user_guide_src/source/changelogs/v4.4.0.rst

+8
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ Added Parameters
109109
- **Routing:** The third parameter ``Routing $routing`` has been added to
110110
``RouteCollection::__construct()``.
111111

112+
Removed Parameters
113+
------------------
114+
115+
- **Services:** The second parameter ``$request`` and the third parameter
116+
``$response`` in ``Services::exceptions()`` have been removed.
117+
- **Error Handling:** The second parameter ``$request`` and the third parameter
118+
``$response`` in ``CodeIgniter\Debug\Exceptions::__construct()`` have been removed.
119+
112120
Return Type Changes
113121
-------------------
114122

0 commit comments

Comments
 (0)