Skip to content

Commit 980bdad

Browse files
committed
refactor(routing): use constructor property promotion
1 parent e49f84b commit 980bdad

15 files changed

+76
-112
lines changed

src/Symfony/Component/Routing/CompiledRoute.php

+10-19
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@
1818
*/
1919
class CompiledRoute implements \Serializable
2020
{
21-
private array $variables;
22-
private array $tokens;
23-
private string $staticPrefix;
24-
private string $regex;
25-
private array $pathVariables;
26-
private array $hostVariables;
27-
private ?string $hostRegex;
28-
private array $hostTokens;
29-
3021
/**
3122
* @param string $staticPrefix The static prefix of the compiled route
3223
* @param string $regex The regular expression to use to match this route
@@ -37,16 +28,16 @@ class CompiledRoute implements \Serializable
3728
* @param array $hostVariables An array of host variables
3829
* @param array $variables An array of variables (variables defined in the path and in the host patterns)
3930
*/
40-
public function __construct(string $staticPrefix, string $regex, array $tokens, array $pathVariables, ?string $hostRegex = null, array $hostTokens = [], array $hostVariables = [], array $variables = [])
41-
{
42-
$this->staticPrefix = $staticPrefix;
43-
$this->regex = $regex;
44-
$this->tokens = $tokens;
45-
$this->pathVariables = $pathVariables;
46-
$this->hostRegex = $hostRegex;
47-
$this->hostTokens = $hostTokens;
48-
$this->hostVariables = $hostVariables;
49-
$this->variables = $variables;
31+
public function __construct(
32+
private string $staticPrefix,
33+
private string $regex,
34+
private array $tokens,
35+
private array $pathVariables,
36+
private ?string $hostRegex = null,
37+
private array $hostTokens = [],
38+
private array $hostVariables = [],
39+
private array $variables = [],
40+
) {
5041
}
5142

5243
public function __serialize(): array

src/Symfony/Component/Routing/Exception/MissingMandatoryParametersException.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@
1919
*/
2020
class MissingMandatoryParametersException extends \InvalidArgumentException implements ExceptionInterface
2121
{
22-
private string $routeName = '';
23-
private array $missingParameters = [];
24-
2522
/**
2623
* @param string[] $missingParameters
2724
*/
28-
public function __construct(string $routeName = '', array $missingParameters = [], int $code = 0, ?\Throwable $previous = null)
29-
{
30-
$this->routeName = $routeName;
31-
$this->missingParameters = $missingParameters;
25+
public function __construct(
26+
private string $routeName = '',
27+
private array $missingParameters = [],
28+
int $code = 0,
29+
?\Throwable $previous = null,
30+
) {
3231
$message = sprintf('Some mandatory parameters are missing ("%s") to generate a URL for route "%s".', implode('", "', $missingParameters), $routeName);
3332

3433
parent::__construct($message, $code, $previous);

src/Symfony/Component/Routing/Generator/CompiledUrlGenerator.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
*/
2121
class CompiledUrlGenerator extends UrlGenerator
2222
{
23-
private array $compiledRoutes = [];
24-
private ?string $defaultLocale;
25-
26-
public function __construct(array $compiledRoutes, RequestContext $context, ?LoggerInterface $logger = null, ?string $defaultLocale = null)
27-
{
28-
$this->compiledRoutes = $compiledRoutes;
23+
public function __construct(
24+
private array $compiledRoutes = [],
25+
RequestContext $context,
26+
?LoggerInterface $logger = null,
27+
private ?string $defaultLocale = null,
28+
) {
2929
$this->context = $context;
3030
$this->logger = $logger;
31-
$this->defaultLocale = $defaultLocale;
3231
}
3332

3433
public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string

src/Symfony/Component/Routing/Generator/Dumper/GeneratorDumper.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
*/
2121
abstract class GeneratorDumper implements GeneratorDumperInterface
2222
{
23-
private RouteCollection $routes;
24-
25-
public function __construct(RouteCollection $routes)
26-
{
27-
$this->routes = $routes;
23+
public function __construct(
24+
private RouteCollection $routes,
25+
) {
2826
}
2927

3028
public function getRoutes(): RouteCollection

src/Symfony/Component/Routing/Generator/UrlGenerator.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
4242
'%2A' => '*',
4343
];
4444

45-
protected RouteCollection $routes;
46-
protected RequestContext $context;
4745
protected ?bool $strictRequirements = true;
48-
protected ?LoggerInterface $logger;
49-
50-
private ?string $defaultLocale;
5146

5247
/**
5348
* This array defines the characters (besides alphanumeric ones) that will not be percent-encoded in the path segment of the generated URL.
@@ -78,12 +73,12 @@ class UrlGenerator implements UrlGeneratorInterface, ConfigurableRequirementsInt
7873
'%7C' => '|',
7974
];
8075

81-
public function __construct(RouteCollection $routes, RequestContext $context, ?LoggerInterface $logger = null, ?string $defaultLocale = null)
82-
{
83-
$this->routes = $routes;
84-
$this->context = $context;
85-
$this->logger = $logger;
86-
$this->defaultLocale = $defaultLocale;
76+
public function __construct(
77+
protected RouteCollection $routes,
78+
protected RequestContext $context,
79+
protected ?LoggerInterface $logger = null,
80+
private ?string $defaultLocale = null,
81+
) {
8782
}
8883

8984
public function setContext(RequestContext $context): void

src/Symfony/Component/Routing/Loader/AttributeFileLoader.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@
2525
*/
2626
class AttributeFileLoader extends FileLoader
2727
{
28-
protected AttributeClassLoader $loader;
29-
30-
public function __construct(FileLocatorInterface $locator, AttributeClassLoader $loader)
31-
{
28+
public function __construct(
29+
FileLocatorInterface $locator,
30+
protected AttributeClassLoader $loader,
31+
) {
3232
if (!\function_exists('token_get_all')) {
3333
throw new \LogicException('The Tokenizer extension is required for the routing attribute loader.');
3434
}
3535

3636
parent::__construct($locator);
37-
38-
$this->loader = $loader;
3937
}
4038

4139
/**

src/Symfony/Component/Routing/Loader/Configurator/AliasConfigurator.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

1717
class AliasConfigurator
1818
{
19-
private Alias $alias;
20-
21-
public function __construct(Alias $alias)
22-
{
23-
$this->alias = $alias;
19+
public function __construct(
20+
private Alias $alias,
21+
) {
2422
}
2523

2624
/**

src/Symfony/Component/Routing/Loader/Configurator/CollectionConfigurator.php

+6-8
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,17 @@ class CollectionConfigurator
2323
use Traits\HostTrait;
2424
use Traits\RouteTrait;
2525

26-
private RouteCollection $parent;
27-
private ?CollectionConfigurator $parentConfigurator;
28-
private ?array $parentPrefixes;
2926
private string|array|null $host = null;
3027

31-
public function __construct(RouteCollection $parent, string $name, ?self $parentConfigurator = null, ?array $parentPrefixes = null)
32-
{
33-
$this->parent = $parent;
28+
public function __construct(
29+
private RouteCollection $parent,
30+
string $name,
31+
private ?self $parentConfigurator = null, // for GC control
32+
private ?array $parentPrefixes = null,
33+
) {
3434
$this->name = $name;
3535
$this->collection = new RouteCollection();
3636
$this->route = new Route('');
37-
$this->parentConfigurator = $parentConfigurator; // for GC control
38-
$this->parentPrefixes = $parentPrefixes;
3937
}
4038

4139
public function __sleep(): array

src/Symfony/Component/Routing/Loader/Configurator/ImportConfigurator.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ class ImportConfigurator
2222
use Traits\PrefixTrait;
2323
use Traits\RouteTrait;
2424

25-
private RouteCollection $parent;
26-
27-
public function __construct(RouteCollection $parent, RouteCollection $route)
28-
{
29-
$this->parent = $parent;
25+
public function __construct(
26+
private RouteCollection $parent,
27+
RouteCollection $route,
28+
) {
3029
$this->route = $route;
3130
}
3231

src/Symfony/Component/Routing/Loader/Configurator/RouteConfigurator.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ class RouteConfigurator
2222
use Traits\HostTrait;
2323
use Traits\RouteTrait;
2424

25-
protected ?CollectionConfigurator $parentConfigurator;
26-
27-
public function __construct(RouteCollection $collection, RouteCollection $route, string $name = '', ?CollectionConfigurator $parentConfigurator = null, ?array $prefixes = null)
28-
{
25+
public function __construct(
26+
RouteCollection $collection,
27+
RouteCollection $route,
28+
string $name = '',
29+
protected ?CollectionConfigurator $parentConfigurator = null, // for GC control
30+
?array $prefixes = null,
31+
) {
2932
$this->collection = $collection;
3033
$this->route = $route;
3134
$this->name = $name;
32-
$this->parentConfigurator = $parentConfigurator; // for GC control
3335
$this->prefixes = $prefixes;
3436
}
3537

src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@ class RoutingConfigurator
2121
{
2222
use Traits\AddTrait;
2323

24-
private PhpFileLoader $loader;
25-
private string $path;
26-
private string $file;
27-
private ?string $env;
28-
29-
public function __construct(RouteCollection $collection, PhpFileLoader $loader, string $path, string $file, ?string $env = null)
30-
{
24+
public function __construct(
25+
RouteCollection $collection,
26+
private PhpFileLoader $loader,
27+
private string $path,
28+
private string $file,
29+
private ?string $env = null,
30+
) {
3131
$this->collection = $collection;
32-
$this->loader = $loader;
33-
$this->path = $path;
34-
$this->file = $file;
35-
$this->env = $env;
3632
}
3733

3834
/**

src/Symfony/Component/Routing/Loader/ContainerLoader.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
*/
2121
class ContainerLoader extends ObjectLoader
2222
{
23-
private ContainerInterface $container;
24-
25-
public function __construct(ContainerInterface $container, ?string $env = null)
26-
{
27-
$this->container = $container;
23+
public function __construct(
24+
private ContainerInterface $container,
25+
?string $env = null,
26+
) {
2827
parent::__construct($env);
2928
}
3029

src/Symfony/Component/Routing/Matcher/Dumper/MatcherDumper.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
*/
2121
abstract class MatcherDumper implements MatcherDumperInterface
2222
{
23-
private RouteCollection $routes;
24-
25-
public function __construct(RouteCollection $routes)
26-
{
27-
$this->routes = $routes;
23+
public function __construct(
24+
private RouteCollection $routes,
25+
) {
2826
}
2927

3028
public function getRoutes(): RouteCollection

src/Symfony/Component/Routing/Matcher/ExpressionLanguageProvider.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
*/
2323
class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
2424
{
25-
private ServiceProviderInterface $functions;
26-
27-
public function __construct(ServiceProviderInterface $functions)
28-
{
29-
$this->functions = $functions;
25+
public function __construct(
26+
private ServiceProviderInterface $functions,
27+
) {
3028
}
3129

3230
public function getFunctions(): array

src/Symfony/Component/Routing/Matcher/UrlMatcher.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
3232
public const REQUIREMENT_MISMATCH = 1;
3333
public const ROUTE_MATCH = 2;
3434

35-
protected RequestContext $context;
36-
3735
/**
3836
* Collects HTTP methods that would be allowed for the request.
3937
*/
@@ -45,8 +43,6 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
4543
* @internal
4644
*/
4745
protected array $allowSchemes = [];
48-
49-
protected RouteCollection $routes;
5046
protected ?Request $request = null;
5147
protected ExpressionLanguage $expressionLanguage;
5248

@@ -55,10 +51,10 @@ class UrlMatcher implements UrlMatcherInterface, RequestMatcherInterface
5551
*/
5652
protected array $expressionLanguageProviders = [];
5753

58-
public function __construct(RouteCollection $routes, RequestContext $context)
59-
{
60-
$this->routes = $routes;
61-
$this->context = $context;
54+
public function __construct(
55+
protected RouteCollection $routes,
56+
protected RequestContext $context,
57+
) {
6258
}
6359

6460
public function setContext(RequestContext $context): void

0 commit comments

Comments
 (0)