Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c4f1ffc

Browse filesBrowse files
committed
Update Processors to mark them final/internal and use CompatibilityProcessor to avoid BC breaks
1 parent 72bbf66 commit c4f1ffc
Copy full SHA for c4f1ffc

17 files changed

+330
-31
lines changed
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Monolog\Formatter;
13+
14+
use Monolog\Logger;
15+
use Monolog\LogRecord;
16+
17+
if (Logger::API >= 3) {
18+
/**
19+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
20+
*
21+
* @author Jordi Boggiano <j.boggiano@seld.be>
22+
*
23+
* @internal
24+
*/
25+
trait CompatibilityFormatter
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function format(LogRecord $record): mixed
31+
{
32+
return $this->doFormat($record);
33+
}
34+
35+
abstract private function doFormat(array|LogRecord $record): mixed;
36+
}
37+
} else {
38+
/**
39+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
40+
*
41+
* @author Jordi Boggiano <j.boggiano@seld.be>
42+
*
43+
* @internal
44+
*/
45+
trait CompatibilityFormatter
46+
{
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function format(array $record): mixed
51+
{
52+
return $this->doFormat($record);
53+
}
54+
55+
abstract private function doFormat(array|LogRecord $record): mixed;
56+
}
57+
}

‎src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Formatter/ConsoleFormatter.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
*/
2929
class ConsoleFormatter implements FormatterInterface
3030
{
31+
use CompatibilityFormatter;
32+
3133
public const SIMPLE_FORMAT = "%datetime% %start_tag%%level_name%%end_tag% <comment>[%channel%]</> %message%%context%%extra%\n";
3234
public const SIMPLE_DATE = 'H:i:s';
3335

@@ -99,10 +101,7 @@ public function formatBatch(array $records): mixed
99101
return $records;
100102
}
101103

102-
/**
103-
* {@inheritdoc}
104-
*/
105-
public function format(array|LogRecord $record): mixed
104+
private function doFormat(array|LogRecord $record): mixed
106105
{
107106
if ($record instanceof LogRecord) {
108107
$record = $record->toArray();

‎src/Symfony/Bridge/Monolog/Formatter/VarDumperFormatter.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Formatter/VarDumperFormatter.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
*/
2121
class VarDumperFormatter implements FormatterInterface
2222
{
23+
use CompatibilityFormatter;
24+
2325
private VarCloner $cloner;
2426

2527
public function __construct(VarCloner $cloner = null)
2628
{
2729
$this->cloner = $cloner ?? new VarCloner();
2830
}
2931

30-
/**
31-
* {@inheritdoc}
32-
*/
33-
public function format(array|LogRecord $record): mixed
32+
private function doFormat(array|LogRecord $record): mixed
3433
{
3534
if ($record instanceof LogRecord) {
3635
$record = $record->toArray();
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Monolog\Handler;
13+
14+
use Monolog\Logger;
15+
use Monolog\LogRecord;
16+
17+
if (Logger::API >= 3) {
18+
/**
19+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
20+
*
21+
* @author Jordi Boggiano <j.boggiano@seld.be>
22+
*
23+
* @internal
24+
*/
25+
trait CompatibilityHandler
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
public function handle(LogRecord $record): bool
31+
{
32+
return $this->doHandle($record);
33+
}
34+
35+
abstract private function doHandle(array|LogRecord $record): bool;
36+
}
37+
} else {
38+
/**
39+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
40+
*
41+
* @author Jordi Boggiano <j.boggiano@seld.be>
42+
*
43+
* @internal
44+
*/
45+
trait CompatibilityHandler
46+
{
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function handle(array $record): bool
51+
{
52+
return $this->doHandle($record);
53+
}
54+
55+
abstract private function doHandle(array|LogRecord $record): bool;
56+
}
57+
}
+57Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Monolog\Handler;
13+
14+
use Monolog\Logger;
15+
use Monolog\LogRecord;
16+
17+
if (Logger::API >= 3) {
18+
/**
19+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
20+
*
21+
* @author Jordi Boggiano <j.boggiano@seld.be>
22+
*
23+
* @internal
24+
*/
25+
trait CompatibilityProcessingHandler
26+
{
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function write(LogRecord $record): void
31+
{
32+
$this->doWrite($record);
33+
}
34+
35+
abstract private function doWrite(array|LogRecord $record): void;
36+
}
37+
} else {
38+
/**
39+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
40+
*
41+
* @author Jordi Boggiano <j.boggiano@seld.be>
42+
*
43+
* @internal
44+
*/
45+
trait CompatibilityProcessingHandler
46+
{
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
protected function write(array $record): void
51+
{
52+
$this->doWrite($record);
53+
}
54+
55+
abstract private function doWrite(array|LogRecord $record): void;
56+
}
57+
}

‎src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Handler/ConsoleHandler.php
+51-6Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,48 @@
2525
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
2626
use Symfony\Component\VarDumper\Dumper\CliDumper;
2727

28+
if (Logger::API >= 3) {
29+
/**
30+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
31+
*
32+
* @author Jordi Boggiano <j.boggiano@seld.be>
33+
*
34+
* @internal
35+
*/
36+
trait CompatibilityIsHandlingHandler
37+
{
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function isHandling(LogRecord $record): bool
42+
{
43+
return $this->doIsHandling($record);
44+
}
45+
46+
abstract private function doIsHandling(array|LogRecord $record): bool;
47+
}
48+
} else {
49+
/**
50+
* The base class for compatibility between Monolog 3 LogRecord and Monolog 1/2 array records.
51+
*
52+
* @author Jordi Boggiano <j.boggiano@seld.be>
53+
*
54+
* @internal
55+
*/
56+
trait CompatibilityIsHandlingHandler
57+
{
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
public function isHandling(array $record): bool
62+
{
63+
return $this->doIsHandling($record);
64+
}
65+
66+
abstract private function doIsHandling(array|LogRecord $record): bool;
67+
}
68+
}
69+
2870
/**
2971
* Writes logs to the console output depending on its verbosity setting.
3072
*
@@ -41,9 +83,15 @@
4183
* This mapping can be customized with the $verbosityLevelMap constructor parameter.
4284
*
4385
* @author Tobias Schultze <http://tobion.de>
86+
*
87+
* @final
4488
*/
4589
class ConsoleHandler extends AbstractProcessingHandler implements EventSubscriberInterface
4690
{
91+
use CompatibilityHandler;
92+
use CompatibilityProcessingHandler;
93+
use CompatibilityIsHandlingHandler;
94+
4795
private ?OutputInterface $output;
4896
private array $verbosityLevelMap = [
4997
OutputInterface::VERBOSITY_QUIET => Logger::ERROR,
@@ -76,15 +124,15 @@ public function __construct(OutputInterface $output = null, bool $bubble = true,
76124
/**
77125
* {@inheritdoc}
78126
*/
79-
public function isHandling(array|LogRecord $record): bool
127+
private function doIsHandling(array|LogRecord $record): bool
80128
{
81129
return $this->updateLevel() && parent::isHandling($record);
82130
}
83131

84132
/**
85133
* {@inheritdoc}
86134
*/
87-
public function handle(array|LogRecord $record): bool
135+
private function doHandle(array|LogRecord $record): bool
88136
{
89137
// we have to update the logging level each time because the verbosity of the
90138
// console output might have changed in the meantime (it is not immutable)
@@ -142,10 +190,7 @@ public static function getSubscribedEvents(): array
142190
];
143191
}
144192

145-
/**
146-
* {@inheritdoc}
147-
*/
148-
protected function write(array|LogRecord $record): void
193+
private function doWrite(array|LogRecord $record): void
149194
{
150195
// at this point we've determined for sure that we want to output the record, so use the output's own verbosity
151196
$this->output->write((string) $record['formatted'], false, $this->output->getVerbosity());

‎src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Handler/ElasticsearchLogstashHandler.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@
4242
* stack is recommended.
4343
*
4444
* @author Grégoire Pineau <lyrixx@lyrixx.info>
45+
*
46+
* @final
4547
*/
4648
class ElasticsearchLogstashHandler extends AbstractHandler
4749
{
50+
use CompatibilityHandler;
51+
4852
use FormattableHandlerTrait;
4953
use ProcessableHandlerTrait;
5054

@@ -70,7 +74,7 @@ public function __construct(string $endpoint = 'http://127.0.0.1:9200', string $
7074
$this->responses = new \SplObjectStorage();
7175
}
7276

73-
public function handle(array|LogRecord $record): bool
77+
private function doHandle(array|LogRecord $record): bool
7478
{
7579
if (!$this->isHandling($record)) {
7680
return false;

‎src/Symfony/Bridge/Monolog/Handler/MailerHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Handler/MailerHandler.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@
2424

2525
/**
2626
* @author Alexander Borisov <boshurik@gmail.com>
27+
*
28+
* @final
2729
*/
2830
class MailerHandler extends AbstractProcessingHandler
2931
{
32+
use CompatibilityProcessingHandler;
33+
3034
private MailerInterface $mailer;
3135
private \Closure|Email $messageTemplate;
3236

@@ -70,7 +74,7 @@ public function handleBatch(array $records): void
7074
/**
7175
* {@inheritdoc}
7276
*/
73-
protected function write(array|LogRecord $record): void
77+
private function doWrite(array|LogRecord $record): void
7478
{
7579
$this->send((string) $record['formatted'], [$record]);
7680
}

‎src/Symfony/Bridge/Monolog/Handler/NotifierHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Monolog/Handler/NotifierHandler.php
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@
2222
* Uses Notifier as a log handler.
2323
*
2424
* @author Fabien Potencier <fabien@symfony.com>
25+
*
26+
* @final
2527
*/
2628
class NotifierHandler extends AbstractHandler
2729
{
30+
use CompatibilityHandler;
31+
2832
private NotifierInterface $notifier;
2933

3034
public function __construct(NotifierInterface $notifier, string|int|Level|LevelName $level = Logger::ERROR, bool $bubble = true)
@@ -34,7 +38,7 @@ public function __construct(NotifierInterface $notifier, string|int|Level|LevelN
3438
parent::__construct(Logger::toMonologLevel($level) < Logger::ERROR ? Logger::ERROR : $level, $bubble);
3539
}
3640

37-
public function handle(array|LogRecord $record): bool
41+
private function doHandle(array|LogRecord $record): bool
3842
{
3943
if (!$this->isHandling($record)) {
4044
return false;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.