Skip to content

Commit 8a78dc2

Browse files
committed
use constructor property promotion
1 parent 665f39f commit 8a78dc2

7 files changed

+28
-87
lines changed

ContainerAwareEventManager.php

+4-11
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

DependencyInjection/CompilerPass/RegisterMappingsPass.php

+8-49
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
}

Form/DoctrineOrmExtension.php

+3-5
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

Form/DoctrineOrmTypeGuesser.php

+3-5
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

Form/Type/DoctrineType.php

+3-5
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

Messenger/AbstractDoctrineMiddleware.php

+4-7
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

Validator/DoctrineInitializer.php

+3-5
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

0 commit comments

Comments
 (0)