Skip to content

Commit fbcdba1

Browse files
committed
minor symfony#57226 [DoctrineBridge][MonologBridge][TwigBridge] use constructor property promotion (xabbuh)
This PR was merged into the 7.2 branch. Discussion ---------- [DoctrineBridge][MonologBridge][TwigBridge] use constructor property promotion | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 5be6afc use constructor property promotion
2 parents 6609544 + 5be6afc commit fbcdba1

15 files changed

+63
-127
lines changed

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,18 @@
2323
*/
2424
class ContainerAwareEventManager extends EventManager
2525
{
26-
/**
27-
* Map of registered listeners.
28-
*
29-
* <event> => <listeners>
30-
*/
31-
private array $listeners = [];
3226
private array $initialized = [];
3327
private bool $initializedSubscribers = false;
3428
private array $initializedHashMapping = [];
3529
private array $methods = [];
36-
private ContainerInterface $container;
3730

3831
/**
3932
* @param list<array{string[], string|object}> $listeners List of [events, listener] tuples
4033
*/
41-
public function __construct(ContainerInterface $container, array $listeners = [])
42-
{
43-
$this->container = $container;
44-
$this->listeners = $listeners;
34+
public function __construct(
35+
private ContainerInterface $container,
36+
private array $listeners = [],
37+
) {
4538
}
4639

4740
public function dispatchEvent(string $eventName, ?EventArgs $eventArgs = null): void

src/Symfony/Bridge/Doctrine/DependencyInjection/CompilerPass/RegisterMappingsPass.php

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -32,41 +32,6 @@
3232
*/
3333
abstract class RegisterMappingsPass implements CompilerPassInterface
3434
{
35-
/**
36-
* DI object for the driver to use, either a service definition for a
37-
* private service or a reference for a public service.
38-
*/
39-
protected Definition|Reference $driver;
40-
41-
/**
42-
* List of namespaces handled by the driver.
43-
*
44-
* @var string[]
45-
*/
46-
protected array $namespaces;
47-
48-
/**
49-
* List of potential container parameters that hold the object manager name
50-
* to register the mappings with the correct metadata driver, for example
51-
* ['acme.manager', 'doctrine.default_entity_manager'].
52-
*
53-
* @var string[]
54-
*/
55-
protected array $managerParameters;
56-
57-
/**
58-
* Naming pattern of the metadata chain driver service ids, for example
59-
* 'doctrine.orm.%s_metadata_driver'.
60-
*/
61-
protected string $driverPattern;
62-
63-
/**
64-
* A name for a parameter in the container. If set, this compiler pass will
65-
* only do anything if the parameter is present. (But regardless of the
66-
* value of that parameter.
67-
*/
68-
protected string|false $enabledParameter;
69-
7035
/**
7136
* The $managerParameters is an ordered list of container parameters that could provide the
7237
* name of the manager to register these namespaces and alias on. The first non-empty name
@@ -79,10 +44,10 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
7944
* @param string[] $namespaces List of namespaces handled by $driver
8045
* @param string[] $managerParameters list of container parameters that could
8146
* hold the manager name
82-
* @param string $driverPattern Pattern for the metadata driver service name
47+
* @param string $driverPattern Pattern for the metadata chain driver service ids (e.g. "doctrine.orm.%s_metadata_driver")
8348
* @param string|false $enabledParameter Service container parameter that must be
84-
* present to enable the mapping. Set to false
85-
* to not do any check, optional.
49+
* present to enable the mapping (regardless of the
50+
* parameter value). Pass false to not do any check.
8651
* @param string $configurationPattern Pattern for the Configuration service name,
8752
* for example 'doctrine.orm.%s_configuration'.
8853
* @param string $registerAliasMethodName Method name to call on the configuration service. This
@@ -91,21 +56,15 @@ abstract class RegisterMappingsPass implements CompilerPassInterface
9156
* @param string[] $aliasMap Map of alias to namespace
9257
*/
9358
public function __construct(
94-
Definition|Reference $driver,
95-
array $namespaces,
96-
array $managerParameters,
97-
string $driverPattern,
98-
string|false $enabledParameter = false,
59+
protected Definition|Reference $driver,
60+
protected array $namespaces,
61+
protected array $managerParameters,
62+
protected string $driverPattern,
63+
protected string|false $enabledParameter = false,
9964
private readonly string $configurationPattern = '',
10065
private readonly string $registerAliasMethodName = '',
10166
private readonly array $aliasMap = [],
10267
) {
103-
$this->driver = $driver;
104-
$this->namespaces = $namespaces;
105-
$this->managerParameters = $managerParameters;
106-
$this->driverPattern = $driverPattern;
107-
$this->enabledParameter = $enabledParameter;
108-
10968
if ($aliasMap && (!$configurationPattern || !$registerAliasMethodName)) {
11069
throw new \InvalidArgumentException('configurationPattern and registerAliasMethodName are required to register namespace alias.');
11170
}

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmExtension.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818

1919
class DoctrineOrmExtension extends AbstractExtension
2020
{
21-
protected ManagerRegistry $registry;
22-
23-
public function __construct(ManagerRegistry $registry)
24-
{
25-
$this->registry = $registry;
21+
public function __construct(
22+
protected ManagerRegistry $registry,
23+
) {
2624
}
2725

2826
protected function loadTypes(): array

src/Symfony/Bridge/Doctrine/Form/DoctrineOrmTypeGuesser.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@
3838

3939
class DoctrineOrmTypeGuesser implements FormTypeGuesserInterface
4040
{
41-
protected ManagerRegistry $registry;
42-
4341
private array $cache = [];
4442

45-
public function __construct(ManagerRegistry $registry)
46-
{
47-
$this->registry = $registry;
43+
public function __construct(
44+
protected ManagerRegistry $registry,
45+
) {
4846
}
4947

5048
public function guessType(string $class, string $property): ?TypeGuess

src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131

3232
abstract class DoctrineType extends AbstractType implements ResetInterface
3333
{
34-
protected ManagerRegistry $registry;
35-
3634
/**
3735
* @var IdReader[]
3836
*/
@@ -89,9 +87,9 @@ public function getQueryBuilderPartsForCachingHash(object $queryBuilder): ?array
8987
return null;
9088
}
9189

92-
public function __construct(ManagerRegistry $registry)
93-
{
94-
$this->registry = $registry;
90+
public function __construct(
91+
protected ManagerRegistry $registry,
92+
) {
9593
}
9694

9795
public function buildForm(FormBuilderInterface $builder, array $options): void

src/Symfony/Bridge/Doctrine/Messenger/AbstractDoctrineMiddleware.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@
2525
*/
2626
abstract class AbstractDoctrineMiddleware implements MiddlewareInterface
2727
{
28-
protected ManagerRegistry $managerRegistry;
29-
protected ?string $entityManagerName;
30-
31-
public function __construct(ManagerRegistry $managerRegistry, ?string $entityManagerName = null)
32-
{
33-
$this->managerRegistry = $managerRegistry;
34-
$this->entityManagerName = $entityManagerName;
28+
public function __construct(
29+
protected ManagerRegistry $managerRegistry,
30+
protected ?string $entityManagerName = null,
31+
) {
3532
}
3633

3734
final public function handle(Envelope $envelope, StackInterface $stack): Envelope

src/Symfony/Bridge/Doctrine/Validator/DoctrineInitializer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@
2121
*/
2222
class DoctrineInitializer implements ObjectInitializerInterface
2323
{
24-
protected ManagerRegistry $registry;
25-
26-
public function __construct(ManagerRegistry $registry)
27-
{
28-
$this->registry = $registry;
24+
public function __construct(
25+
protected ManagerRegistry $registry,
26+
) {
2927
}
3028

3129
public function initialize(object $object): void

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@
4444
*/
4545
final class ConsoleHandler extends AbstractProcessingHandler implements EventSubscriberInterface
4646
{
47-
private ?OutputInterface $output;
4847
private array $verbosityLevelMap = [
4948
OutputInterface::VERBOSITY_QUIET => Level::Error,
5049
OutputInterface::VERBOSITY_NORMAL => Level::Warning,
5150
OutputInterface::VERBOSITY_VERBOSE => Level::Notice,
5251
OutputInterface::VERBOSITY_VERY_VERBOSE => Level::Info,
5352
OutputInterface::VERBOSITY_DEBUG => Level::Debug,
5453
];
55-
private array $consoleFormatterOptions;
5654

5755
/**
5856
* @param OutputInterface|null $output The console output to use (the handler remains disabled when passing null
@@ -61,16 +59,17 @@ final class ConsoleHandler extends AbstractProcessingHandler implements EventSub
6159
* @param array $verbosityLevelMap Array that maps the OutputInterface verbosity to a minimum logging
6260
* level (leave empty to use the default mapping)
6361
*/
64-
public function __construct(?OutputInterface $output = null, bool $bubble = true, array $verbosityLevelMap = [], array $consoleFormatterOptions = [])
65-
{
62+
public function __construct(
63+
private ?OutputInterface $output = null,
64+
bool $bubble = true,
65+
array $verbosityLevelMap = [],
66+
private array $consoleFormatterOptions = [],
67+
) {
6668
parent::__construct(Level::Debug, $bubble);
67-
$this->output = $output;
6869

6970
if ($verbosityLevelMap) {
7071
$this->verbosityLevelMap = $verbosityLevelMap;
7172
}
72-
73-
$this->consoleFormatterOptions = $consoleFormatterOptions;
7473
}
7574

7675
public function isHandling(LogRecord $record): bool

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,28 @@ final class ElasticsearchLogstashHandler extends AbstractHandler
4646
use FormattableHandlerTrait;
4747
use ProcessableHandlerTrait;
4848

49-
private string $endpoint;
50-
private string $index;
5149
private HttpClientInterface $client;
52-
private string $elasticsearchVersion;
5350

5451
/**
5552
* @var \SplObjectStorage<ResponseInterface, null>
5653
*/
5754
private \SplObjectStorage $responses;
5855

59-
public function __construct(string $endpoint = 'http://127.0.0.1:9200', string $index = 'monolog', ?HttpClientInterface $client = null, string|int|Level $level = Level::Debug, bool $bubble = true, string $elasticsearchVersion = '1.0.0')
60-
{
56+
public function __construct(
57+
private string $endpoint = 'http://127.0.0.1:9200',
58+
private string $index = 'monolog',
59+
?HttpClientInterface $client = null,
60+
string|int|Level $level = Level::Debug,
61+
bool $bubble = true,
62+
private string $elasticsearchVersion = '1.0.0',
63+
) {
6164
if (!interface_exists(HttpClientInterface::class)) {
6265
throw new \LogicException(sprintf('The "%s" handler needs an HTTP client. Try running "composer require symfony/http-client".', __CLASS__));
6366
}
6467

6568
parent::__construct($level, $bubble);
66-
$this->endpoint = $endpoint;
67-
$this->index = $index;
6869
$this->client = $client ?: HttpClient::create(['timeout' => 1]);
6970
$this->responses = new \SplObjectStorage();
70-
$this->elasticsearchVersion = $elasticsearchVersion;
7171
}
7272

7373
public function handle(LogRecord $record): bool

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@
2525
*/
2626
final class MailerHandler extends AbstractProcessingHandler
2727
{
28-
private MailerInterface $mailer;
2928
private \Closure|Email $messageTemplate;
3029

31-
public function __construct(MailerInterface $mailer, callable|Email $messageTemplate, string|int|Level $level = Level::Debug, bool $bubble = true)
32-
{
30+
public function __construct(
31+
private MailerInterface $mailer,
32+
callable|Email $messageTemplate,
33+
string|int|Level $level = Level::Debug,
34+
bool $bubble = true,
35+
) {
3336
parent::__construct($level, $bubble);
3437

35-
$this->mailer = $mailer;
3638
$this->messageTemplate = $messageTemplate instanceof Email ? $messageTemplate : $messageTemplate(...);
3739
}
3840

0 commit comments

Comments
 (0)