Skip to content

[MonologBridge] Remove deprecated code #41301

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

Merged
merged 1 commit into from
May 23, 2021
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
6 changes: 6 additions & 0 deletions src/Symfony/Bridge/Monolog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

6.0
---

* The `$actionLevel` constructor argument of `NotFoundActivationStrategy` has been replaced by the `$inner` one which expects an `ActivationStrategyInterface` to decorate instead
* The `$actionLevel` constructor argument of `HttpCodeActivationStrategy` has been replaced by the `$inner` one which expects an `ActivationStrategyInterface` to decorate instead

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bridge\Monolog\Handler\FingersCrossed;

use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Exception\HttpException;

Expand All @@ -21,28 +20,17 @@
*
* @author Shaun Simmons <shaun@envysphere.com>
* @author Pierrick Vignand <pierrick.vignand@gmail.com>
*
* @final
*/
class HttpCodeActivationStrategy extends ErrorLevelActivationStrategy implements ActivationStrategyInterface
final class HttpCodeActivationStrategy implements ActivationStrategyInterface
{
private $inner;
private $exclusions;
private $requestStack;

/**
* @param array $exclusions each exclusion must have a "code" and "urls" keys
* @param ActivationStrategyInterface|int|string $inner an ActivationStrategyInterface to decorate
* @param array $exclusions each exclusion must have a "code" and "urls" keys
*/
public function __construct(RequestStack $requestStack, array $exclusions, $inner)
{
if (!$inner instanceof ActivationStrategyInterface) {
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);

$actionLevel = $inner;
$inner = new ErrorLevelActivationStrategy($actionLevel);
}

public function __construct(
private RequestStack $requestStack,
private array $exclusions,
private ActivationStrategyInterface $inner,
) {
foreach ($exclusions as $exclusion) {
if (!\array_key_exists('code', $exclusion)) {
throw new \LogicException('An exclusion must have a "code" key.');
Expand All @@ -51,10 +39,6 @@ public function __construct(RequestStack $requestStack, array $exclusions, $inne
throw new \LogicException('An exclusion must have a "urls" key.');
}
}

$this->inner = $inner;
$this->requestStack = $requestStack;
$this->exclusions = $exclusions;
}

public function isHandlerActivated(array $record): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bridge\Monolog\Handler\FingersCrossed;

use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Exception\HttpException;

Expand All @@ -22,29 +21,16 @@
* @author Jordi Boggiano <j.boggiano@seld.be>
* @author Fabien Potencier <fabien@symfony.com>
* @author Pierrick Vignand <pierrick.vignand@gmail.com>
*
* @final
*/
class NotFoundActivationStrategy extends ErrorLevelActivationStrategy implements ActivationStrategyInterface
final class NotFoundActivationStrategy implements ActivationStrategyInterface
{
private $inner;
private $exclude;
private $requestStack;

/**
* @param ActivationStrategyInterface|int|string $inner an ActivationStrategyInterface to decorate
*/
public function __construct(RequestStack $requestStack, array $excludedUrls, $inner)
{
if (!$inner instanceof ActivationStrategyInterface) {
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);

$actionLevel = $inner;
$inner = new ErrorLevelActivationStrategy($actionLevel);
}

$this->inner = $inner;
$this->requestStack = $requestStack;
public function __construct(
private RequestStack $requestStack,
array $excludedUrls,
private ActivationStrategyInterface $inner
) {
$this->exclude = '{('.implode('|', $excludedUrls).')}i';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,6 @@

class HttpCodeActivationStrategyTest extends TestCase
{
/**
* @group legacy
*/
public function testExclusionsWithoutCodeLegacy()
{
$this->expectException(\LogicException::class);
new HttpCodeActivationStrategy(new RequestStack(), [['urls' => []]], Logger::WARNING);
}

/**
* @group legacy
*/
public function testExclusionsWithoutUrlsLegacy()
{
$this->expectException(\LogicException::class);
new HttpCodeActivationStrategy(new RequestStack(), [['code' => 404]], Logger::WARNING);
}

/**
* @dataProvider isActivatedProvider
*
* @group legacy
*/
public function testIsActivatedLegacy($url, $record, $expected)
{
$requestStack = new RequestStack();
$requestStack->push(Request::create($url));

$strategy = new HttpCodeActivationStrategy(
$requestStack,
[
['code' => 403, 'urls' => []],
['code' => 404, 'urls' => []],
['code' => 405, 'urls' => []],
['code' => 400, 'urls' => ['^/400/a', '^/400/b']],
],
Logger::WARNING
);

self::assertEquals($expected, $strategy->isHandlerActivated($record));
}

public function testExclusionsWithoutCode()
{
$this->expectException(\LogicException::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@

class NotFoundActivationStrategyTest extends TestCase
{
/**
* @dataProvider isActivatedProvider
*
* @group legacy
*/
public function testIsActivatedLegacy(string $url, array $record, bool $expected)
{
$requestStack = new RequestStack();
$requestStack->push(Request::create($url));

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

self::assertEquals($expected, $strategy->isHandlerActivated($record));
}

/**
* @dataProvider isActivatedProvider
*/
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Bridge/Monolog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"php": ">=8.0.2",
"monolog/monolog": "^1.25.1|^2",
"symfony/service-contracts": "^1.1|^2",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/deprecation-contracts": "^2.1"
"symfony/http-kernel": "^5.4|^6.0"
},
"require-dev": {
"symfony/console": "^5.4|^6.0",
Expand Down