Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove instantiation of Response in Services::exceptions() #7670

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
* @method static CURLRequest curlrequest($options = [], ResponseInterface $response = null, App $config = null, $getShared = true)
* @method static Email email($config = null, $getShared = true)
* @method static EncrypterInterface encrypter(Encryption $config = null, $getShared = false)
* @method static Exceptions exceptions(ConfigExceptions $config = null, IncomingRequest $request = null, ResponseInterface $response = null, $getShared = true)
* @method static Exceptions exceptions(ConfigExceptions $config = null, $getShared = true)
* @method static Filters filters(ConfigFilters $config = null, $getShared = true)
* @method static Format format(ConfigFormat $config = null, $getShared = true)
* @method static Honeypot honeypot(ConfigHoneyPot $config = null, $getShared = true)
Expand Down
11 changes: 2 additions & 9 deletions system/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,25 +257,18 @@ public static function encrypter(?EncryptionConfig $config = null, $getShared =
* - register_shutdown_function
*
* @return Exceptions
*
* @deprecated The parameter $request and $response are deprecated.
*/
public static function exceptions(
?ExceptionsConfig $config = null,
?IncomingRequest $request = null,
?ResponseInterface $response = null,
bool $getShared = true
) {
if ($getShared) {
return static::getSharedInstance('exceptions', $config, $request, $response);
return static::getSharedInstance('exceptions', $config);
}

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

// @TODO remove instantiation of Response in the future.
$response ??= AppServices::response();

return new Exceptions($config, $request, $response);
return new Exceptions($config);
}

/**
Expand Down
21 changes: 8 additions & 13 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Exceptions
*
* @var int
*
* @deprecated No longer used. Moved to BaseExceptionHandler.
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
*/
public $ob_level;

Expand All @@ -47,7 +47,7 @@ class Exceptions
*
* @var string
*
* @deprecated No longer used. Moved to BaseExceptionHandler.
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
*/
protected $viewPath;

Expand All @@ -74,12 +74,7 @@ class Exceptions

private ?Throwable $exceptionCaughtByExceptionHandler = null;

/**
* @param RequestInterface|null $request
*
* @deprecated The parameter $request and $response are deprecated. No longer used.
*/
public function __construct(ExceptionsConfig $config, $request, ResponseInterface $response) /** @phpstan-ignore-line */
public function __construct(ExceptionsConfig $config)
{
// For backward compatibility
$this->ob_level = ob_get_level();
Expand Down Expand Up @@ -240,7 +235,7 @@ public function shutdownHandler()
*
* @return string The path and filename of the view file to use
*
* @deprecated No longer used. Moved to ExceptionHandler.
* @deprecated 4.4.0 No longer used. Moved to ExceptionHandler.
*/
protected function determineView(Throwable $exception, string $templatePath): string
{
Expand Down Expand Up @@ -268,7 +263,7 @@ protected function determineView(Throwable $exception, string $templatePath): st
/**
* Given an exception and status code will display the error to the client.
*
* @deprecated No longer used. Moved to BaseExceptionHandler.
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
*/
protected function render(Throwable $exception, int $statusCode)
{
Expand Down Expand Up @@ -310,7 +305,7 @@ protected function render(Throwable $exception, int $statusCode)
/**
* Gathers the variables that will be made available to the view.
*
* @deprecated No longer used. Moved to BaseExceptionHandler.
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
*/
protected function collectVars(Throwable $exception, int $statusCode): array
{
Expand Down Expand Up @@ -471,7 +466,7 @@ public static function cleanPath(string $file): string
* Describes memory usage in real-world units. Intended for use
* with memory_get_usage, etc.
*
* @deprecated No longer used. Moved to BaseExceptionHandler.
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
*/
public static function describeMemory(int $bytes): string
{
Expand All @@ -491,7 +486,7 @@ public static function describeMemory(int $bytes): string
*
* @return bool|string
*
* @deprecated No longer used. Moved to BaseExceptionHandler.
* @deprecated 4.4.0 No longer used. Moved to BaseExceptionHandler.
*/
public static function highlightFile(string $file, int $lineNumber, int $lines = 15)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Config/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ public function testNewUnsharedEmailWithNonEmptyConfig(): void

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

public function testNewExceptionsWithNullConfig(): void
{
$actual = Services::exceptions(null, null, null, false);
$actual = Services::exceptions(null, false);
$this->assertInstanceOf(\CodeIgniter\Debug\Exceptions::class, $actual);
}

Expand Down
7 changes: 3 additions & 4 deletions tests/system/Debug/ExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\ReflectionHelper;
use Config\Exceptions as ExceptionsConfig;
use Config\Services;
use ErrorException;
use RuntimeException;

Expand Down Expand Up @@ -52,7 +51,7 @@ protected function setUp(): void
{
parent::setUp();

$this->exception = new Exceptions(new ExceptionsConfig(), Services::request(), Services::response());
$this->exception = new Exceptions(new ExceptionsConfig());
}

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

$this->exception = new Exceptions($config, Services::request(), Services::response());
$this->exception = new Exceptions($config);
$this->exception->initialize();

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

$this->exception = new Exceptions($config, Services::request(), Services::response());
$this->exception = new Exceptions($config);
$this->exception->initialize();

@trigger_error('Hello! I am a deprecation!', E_USER_DEPRECATED);
Expand Down
8 changes: 8 additions & 0 deletions user_guide_src/source/changelogs/v4.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ Added Parameters
- **Routing:** The third parameter ``Routing $routing`` has been added to
``RouteCollection::__construct()``.

Removed Parameters
------------------

- **Services:** The second parameter ``$request`` and the third parameter
``$response`` in ``Services::exceptions()`` have been removed.
- **Error Handling:** The second parameter ``$request`` and the third parameter
``$response`` in ``CodeIgniter\Debug\Exceptions::__construct()`` have been removed.

Return Type Changes
-------------------

Expand Down
Loading