Skip to content
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
5 changes: 4 additions & 1 deletion UPGRADE-7.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ Mime
Routing
-------

* Deprecate `getEnv()` and `setEnv()` methods of the `Symfony\Component\Routing\Attribute\Route` class in favor of the plurialized `getEnvs()` and `setEnvs()` methods
* Deprecate class aliases in the `Annotation` namespace, use attributes instead
* Deprecate getters and setters in attribute classes in favor of public properties

Security
--------
Expand All @@ -90,6 +91,8 @@ Serializer
----------

* Make `AttributeMetadata` and `ClassMetadata` final
* Deprecate class aliases in the `Annotation` namespace, use attributes instead
* Deprecate getters in attribute classes in favor of public properties

String
------
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Routing/Annotation/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
class_exists(\Symfony\Component\Routing\Attribute\Route::class);

if (false) {
/**
* @deprecated since Symfony 7.4, use {@see \Symfony\Component\Routing\Attribute\Route} instead
*/
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class Route extends \Symfony\Component\Routing\Attribute\Route
{
Expand Down
12 changes: 8 additions & 4 deletions src/Symfony/Component/Routing/Attribute/DeprecatedAlias.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,32 @@
class DeprecatedAlias
{
public function __construct(
private string $aliasName,
private string $package,
private string $version,
private string $message = '',
public readonly string $aliasName,
public readonly string $package,
public readonly string $version,
public readonly string $message = '',
) {
}

#[\Deprecated('Use the "message" property instead', 'symfony/routing:7.4')]
public function getMessage(): string
{
return $this->message;
}

#[\Deprecated('Use the "aliasName" property instead', 'symfony/routing:7.4')]
public function getAliasName(): string
{
return $this->aliasName;
}

#[\Deprecated('Use the "package" property instead', 'symfony/routing:7.4')]
public function getPackage(): string
{
return $this->package;
}

#[\Deprecated('Use the "version" property instead', 'symfony/routing:7.4')]
public function getVersion(): string
{
return $this->version;
Expand Down
109 changes: 57 additions & 52 deletions src/Symfony/Component/Routing/Attribute/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
class Route
{
private ?string $path = null;
private array $localizedPaths = [];
private array $methods;
/** @var string[] */
private array $env;
private array $schemes;
/**
* @var (string|DeprecatedAlias)[]
*/
private array $aliases = [];
public array $methods;

/** @var string[] */
public array $envs;

/** @var string[] */
public array $schemes;

/** @var (string|DeprecatedAlias)[] */
public array $aliases = [];

/**
* @param string|array<string,string>|null $path The route path (i.e. "/user/login")
Expand All @@ -50,32 +51,28 @@ class Route
* @param string|DeprecatedAlias|(string|DeprecatedAlias)[] $alias The list of aliases for this route
*/
public function __construct(
string|array|null $path = null,
private ?string $name = null,
private array $requirements = [],
private array $options = [],
private array $defaults = [],
private ?string $host = null,
public string|array|null $path = null,
public ?string $name = null,
public array $requirements = [],
public array $options = [],
public array $defaults = [],
public ?string $host = null,
array|string $methods = [],
array|string $schemes = [],
private ?string $condition = null,
private ?int $priority = null,
public ?string $condition = null,
public ?int $priority = null,
?string $locale = null,
?string $format = null,
?bool $utf8 = null,
?bool $stateless = null,
string|array|null $env = null,
string|DeprecatedAlias|array $alias = [],
) {
if (\is_array($path)) {
$this->localizedPaths = $path;
} else {
$this->path = $path;
}
$this->setMethods($methods);
$this->setSchemes($schemes);
$this->setAliases($alias);
$this->setEnvs((array) $env);
$this->path = $path;
$this->methods = (array) $methods;
$this->schemes = (array) $schemes;
$this->envs = (array) $env;
$this->aliases = \is_array($alias) ? $alias : [$alias];

if (null !== $locale) {
$this->defaults['_locale'] = $locale;
Expand All @@ -94,154 +91,161 @@ public function __construct(
}
}

#[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
public function setPath(string $path): void
{
$this->path = $path;
}

#[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
public function getPath(): ?string
{
return $this->path;
return \is_array($this->path) ? null : $this->path;
}

#[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
public function setLocalizedPaths(array $localizedPaths): void
{
$this->localizedPaths = $localizedPaths;
$this->path = $localizedPaths;
}

#[\Deprecated('Use the "path" property instead', 'symfony/routing:7.4')]
public function getLocalizedPaths(): array
{
return $this->localizedPaths;
return \is_array($this->path) ? $this->path : [];
}

#[\Deprecated('Use the "host" property instead', 'symfony/routing:7.4')]
public function setHost(string $pattern): void
{
$this->host = $pattern;
}

#[\Deprecated('Use the "host" property instead', 'symfony/routing:7.4')]
public function getHost(): ?string
{
return $this->host;
}

#[\Deprecated('Use the "name" property instead', 'symfony/routing:7.4')]
public function setName(string $name): void
{
$this->name = $name;
}

#[\Deprecated('Use the "name" property instead', 'symfony/routing:7.4')]
public function getName(): ?string
{
return $this->name;
}

#[\Deprecated('Use the "requirements" property instead', 'symfony/routing:7.4')]
public function setRequirements(array $requirements): void
{
$this->requirements = $requirements;
}

#[\Deprecated('Use the "requirements" property instead', 'symfony/routing:7.4')]
public function getRequirements(): array
{
return $this->requirements;
}

#[\Deprecated('Use the "options" property instead', 'symfony/routing:7.4')]
public function setOptions(array $options): void
{
$this->options = $options;
}

#[\Deprecated('Use the "options" property instead', 'symfony/routing:7.4')]
public function getOptions(): array
{
return $this->options;
}

#[\Deprecated('Use the "defaults" property instead', 'symfony/routing:7.4')]
public function setDefaults(array $defaults): void
{
$this->defaults = $defaults;
}

#[\Deprecated('Use the "defaults" property instead', 'symfony/routing:7.4')]
public function getDefaults(): array
{
return $this->defaults;
}

#[\Deprecated('Use the "schemes" property instead', 'symfony/routing:7.4')]
public function setSchemes(array|string $schemes): void
{
$this->schemes = (array) $schemes;
}

#[\Deprecated('Use the "schemes" property instead', 'symfony/routing:7.4')]
public function getSchemes(): array
{
return $this->schemes;
}

#[\Deprecated('Use the "methods" property instead', 'symfony/routing:7.4')]
public function setMethods(array|string $methods): void
{
$this->methods = (array) $methods;
}

#[\Deprecated('Use the "methods" property instead', 'symfony/routing:7.4')]
public function getMethods(): array
{
return $this->methods;
}

#[\Deprecated('Use the "condition" property instead', 'symfony/routing:7.4')]
public function setCondition(?string $condition): void
{
$this->condition = $condition;
}

#[\Deprecated('Use the "condition" property instead', 'symfony/routing:7.4')]
public function getCondition(): ?string
{
return $this->condition;
}

#[\Deprecated('Use the "priority" property instead', 'symfony/routing:7.4')]
public function setPriority(int $priority): void
{
$this->priority = $priority;
}

#[\Deprecated('Use the "priority" property instead', 'symfony/routing:7.4')]
public function getPriority(): ?int
{
return $this->priority;
}

/**
* @deprecated since Symfony 7.4, use the {@see setEnvs()} method instead
*/
#[\Deprecated('Use the "envs" property instead', 'symfony/routing:7.4')]
public function setEnv(?string $env): void
{
trigger_deprecation('symfony/routing', '7.4', 'The "%s()" method is deprecated, use "setEnvs()" instead.', __METHOD__);
$this->env = (array) $env;
$this->envs = (array) $env;
}

/**
* @deprecated since Symfony 7.4, use {@see getEnvs()} method instead
*/
#[\Deprecated('Use the "envs" property instead', 'symfony/routing:7.4')]
public function getEnv(): ?string
{
trigger_deprecation('symfony/routing', '7.4', 'The "%s()" method is deprecated, use "getEnvs()" instead.', __METHOD__);
if (!$this->env) {
if (!$this->envs) {
return null;
}
if (\count($this->env) > 1) {
throw new LogicException(\sprintf('The "env" property has %d environments. Use "getEnvs()" to get all of them.', \count($this->env)));
if (\count($this->envs) > 1) {
throw new LogicException(\sprintf('The "env" property has %d environments. Use "getEnvs()" to get all of them.', \count($this->envs)));
}

return $this->env[0];
}

public function setEnvs(array|string $env): void
{
$this->env = (array) $env;
}

public function getEnvs(): array
{
return $this->env;
return $this->envs[0];
}

/**
* @return (string|DeprecatedAlias)[]
*/
#[\Deprecated('Use the "aliases" property instead', 'symfony/routing:7.4')]
public function getAliases(): array
{
return $this->aliases;
Expand All @@ -250,6 +254,7 @@ public function getAliases(): array
/**
* @param string|DeprecatedAlias|(string|DeprecatedAlias)[] $aliases
*/
#[\Deprecated('Use the "aliases" property instead', 'symfony/routing:7.4')]
public function setAliases(string|DeprecatedAlias|array $aliases): void
{
$this->aliases = \is_array($aliases) ? $aliases : [$aliases];
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Routing/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CHANGELOG
* Allow query-specific parameters in `UrlGenerator` using `_query`
* Add support of multiple env names in the `Symfony\Component\Routing\Attribute\Route` attribute
* Add argument `$parameters` to `RequestContext`'s constructor
* Deprecate class aliases in the `Annotation` namespace, use attributes instead
* Deprecate getters and setters in attribute classes in favor of public properties

7.3
---
Expand Down
Loading