Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3dc274

Browse files
bug #62242 [MonologBridge] Accept HttpExceptionInterface in HttpCodeActivationStrategy (GromNaN)
This PR was merged into the 6.4 branch. Discussion ---------- [MonologBridge] Accept HttpExceptionInterface in HttpCodeActivationStrategy | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #60239 | License | MIT Commits ------- c2c34bb [MonologBundle] Accept HttpExceptionInterface in HttpCodeActivationStrategy
2 parents 7c7a677 + c2c34bb commit f3dc274

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/Symfony/Bridge/Monolog/Handler/FingersCrossed/HttpCodeActivationStrategy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
1515
use Monolog\LogRecord;
1616
use Symfony\Component\HttpFoundation\RequestStack;
17-
use Symfony\Component\HttpKernel\Exception\HttpException;
17+
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
1818

1919
/**
2020
* Activation strategy that ignores certain HTTP codes.
@@ -49,7 +49,7 @@ public function isHandlerActivated(array|LogRecord $record): bool
4949
if (
5050
$isActivated
5151
&& isset($record['context']['exception'])
52-
&& $record['context']['exception'] instanceof HttpException
52+
&& $record['context']['exception'] instanceof HttpExceptionInterface
5353
&& ($request = $this->requestStack->getMainRequest())
5454
) {
5555
foreach ($this->exclusions as $exclusion) {

src/Symfony/Bridge/Monolog/Tests/Handler/FingersCrossed/HttpCodeActivationStrategyTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Bridge\Monolog\Tests\RecordFactory;
1919
use Symfony\Component\HttpFoundation\Request;
2020
use Symfony\Component\HttpFoundation\RequestStack;
21-
use Symfony\Component\HttpKernel\Exception\HttpException;
21+
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
2222

2323
class HttpCodeActivationStrategyTest extends TestCase
2424
{
@@ -74,6 +74,23 @@ public static function isActivatedProvider(): array
7474

7575
private static function getContextException(int $code): array
7676
{
77-
return ['exception' => new HttpException($code)];
77+
return ['exception' => new class($code) extends \RuntimeException implements HttpExceptionInterface {
78+
private int $statusCode;
79+
80+
public function __construct(int $statusCode)
81+
{
82+
$this->statusCode = $statusCode;
83+
}
84+
85+
public function getStatusCode(): int
86+
{
87+
return $this->statusCode;
88+
}
89+
90+
public function getHeaders(): array
91+
{
92+
return [];
93+
}
94+
}];
7895
}
7996
}

0 commit comments

Comments
 (0)