Skip to content

Commit d013660

Browse files
committed
fixup! Use composition instead of inheritance in NotFoundActivationStrategy
1 parent f6cb984 commit d013660

File tree

4 files changed

+34
-123
lines changed

4 files changed

+34
-123
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,44 @@
1111

1212
namespace Symfony\Bridge\Monolog\Handler\FingersCrossed;
1313

14+
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
1415
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
1516
use Symfony\Component\HttpFoundation\RequestStack;
1617
use Symfony\Component\HttpKernel\Exception\HttpException;
1718

18-
trigger_deprecation('symfony/monolog-bridge', '5.1', 'The "%s" class is deprecated, use "%s" instead.', NotFoundActivationStrategy::class, NotFoundActivationStrategyDecorator::class);
19-
2019
/**
2120
* Activation strategy that ignores 404s for certain URLs.
2221
*
2322
* @author Jordi Boggiano <j.boggiano@seld.be>
2423
* @author Fabien Potencier <fabien@symfony.com>
25-
*
26-
* @deprecated since Symfony 5.1, Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategyDecorator instead.
24+
* @author Pierrick Vignand <pierrick.vignand@gmail.com>
2725
*/
28-
class NotFoundActivationStrategy extends ErrorLevelActivationStrategy
26+
/* final */ class NotFoundActivationStrategy extends ErrorLevelActivationStrategy implements ActivationStrategyInterface
2927
{
28+
private $inner;
3029
private $exclude;
3130
private $requestStack;
3231

33-
public function __construct(RequestStack $requestStack, array $excludedUrls, $actionLevel)
32+
/**
33+
* @param ActivationStrategyInterface|int|string $inner an ActivationStrategyInterface to decorate
34+
*/
35+
public function __construct(RequestStack $requestStack, array $excludedUrls, $inner)
3436
{
35-
parent::__construct($actionLevel);
37+
if (!$inner instanceof ActivationStrategyInterface) {
38+
trigger_deprecation('symfony/monolog-bridge', '5.2', 'Passing an actionLevel (int|string) as constructor\'s 3rd argument of "%s" is deprecated, "%s" expected.', __CLASS__, ActivationStrategyInterface::class);
39+
40+
$actionLevel = $inner;
41+
$inner = new ErrorLevelActivationStrategy($actionLevel);
42+
}
3643

44+
$this->inner = $inner;
3745
$this->requestStack = $requestStack;
3846
$this->exclude = '{('.implode('|', $excludedUrls).')}i';
3947
}
4048

4149
public function isHandlerActivated(array $record): bool
4250
{
43-
$isActivated = parent::isHandlerActivated($record);
51+
$isActivated = $this->inner->isHandlerActivated($record);
4452

4553
if (
4654
$isActivated

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

Lines changed: 0 additions & 55 deletions
This file was deleted.

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

Lines changed: 0 additions & 56 deletions
This file was deleted.

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Monolog\Tests\Handler\FingersCrossed;
1313

14+
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
1415
use Monolog\Logger;
1516
use PHPUnit\Framework\TestCase;
1617
use Symfony\Bridge\Monolog\Handler\FingersCrossed\NotFoundActivationStrategy;
@@ -25,17 +26,30 @@ class NotFoundActivationStrategyTest extends TestCase
2526
*
2627
* @group legacy
2728
*/
28-
public function testIsActivated($url, $record, $expected)
29+
public function testIsActivatedLegacy(string $url, array $record, bool $expected): void
2930
{
3031
$requestStack = new RequestStack();
3132
$requestStack->push(Request::create($url));
3233

3334
$strategy = new NotFoundActivationStrategy($requestStack, ['^/foo', 'bar'], Logger::WARNING);
3435

35-
$this->assertEquals($expected, $strategy->isHandlerActivated($record));
36+
self::assertEquals($expected, $strategy->isHandlerActivated($record));
3637
}
3738

38-
public function isActivatedProvider()
39+
/**
40+
* @dataProvider isActivatedProvider
41+
*/
42+
public function testIsActivated(string $url, array $record, bool $expected): void
43+
{
44+
$requestStack = new RequestStack();
45+
$requestStack->push(Request::create($url));
46+
47+
$strategy = new NotFoundActivationStrategy($requestStack, ['^/foo', 'bar'], new ErrorLevelActivationStrategy(Logger::WARNING));
48+
49+
self::assertEquals($expected, $strategy->isHandlerActivated($record));
50+
}
51+
52+
public function isActivatedProvider(): array
3953
{
4054
return [
4155
['/test', ['level' => Logger::DEBUG], false],
@@ -50,7 +64,7 @@ public function isActivatedProvider()
5064
];
5165
}
5266

53-
protected function getContextException($code)
67+
protected function getContextException(int $code): array
5468
{
5569
return ['exception' => new HttpException($code)];
5670
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy