-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] Remove deprecation layer #41371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolas-grekas
merged 1 commit into
symfony:6.0
from
derrabus:remove/routing-deprecations
May 27, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,133 +24,59 @@ | |
#[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] | ||
class Route | ||
{ | ||
private $path; | ||
private $localizedPaths = []; | ||
private $name; | ||
private $requirements = []; | ||
private $options = []; | ||
private $defaults = []; | ||
private $host; | ||
private $methods = []; | ||
private $schemes = []; | ||
private $condition; | ||
private $priority; | ||
private $env; | ||
private ?string $path = null; | ||
private array $localizedPaths = []; | ||
private array $methods; | ||
private array $schemes; | ||
|
||
/** | ||
* @param array|string $data data array managed by the Doctrine Annotations library or the path | ||
* @param array|string|null $path | ||
* @param string[] $requirements | ||
* @param string[]|string $methods | ||
* @param string[]|string $schemes | ||
* | ||
* @throws \BadMethodCallException | ||
* @param string[] $requirements | ||
* @param string[]|string $methods | ||
* @param string[]|string $schemes | ||
*/ | ||
public function __construct( | ||
$data = [], | ||
$path = null, | ||
string $name = null, | ||
array $requirements = [], | ||
array $options = [], | ||
array $defaults = [], | ||
string $host = null, | ||
$methods = [], | ||
$schemes = [], | ||
string $condition = null, | ||
int $priority = null, | ||
string | array | null $path = null, | ||
private ?string $name = null, | ||
private array $requirements = [], | ||
private array $options = [], | ||
private array $defaults = [], | ||
private ?string $host = null, | ||
array | string $methods = [], | ||
array | string $schemes = [], | ||
private ?string $condition = null, | ||
private ?int $priority = null, | ||
string $locale = null, | ||
string $format = null, | ||
bool $utf8 = null, | ||
bool $stateless = null, | ||
string $env = null | ||
private ?string $env = null | ||
) { | ||
if (\is_string($data)) { | ||
$data = ['path' => $data]; | ||
} elseif (!\is_array($data)) { | ||
throw new \TypeError(sprintf('"%s": Argument $data is expected to be a string or array, got "%s".', __METHOD__, get_debug_type($data))); | ||
} elseif ([] !== $data) { | ||
$deprecation = false; | ||
foreach ($data as $key => $val) { | ||
if (\in_array($key, ['path', 'name', 'requirements', 'options', 'defaults', 'host', 'methods', 'schemes', 'condition', 'priority', 'locale', 'format', 'utf8', 'stateless', 'env', 'value'])) { | ||
$deprecation = true; | ||
} | ||
} | ||
|
||
if ($deprecation) { | ||
trigger_deprecation('symfony/routing', '5.3', 'Passing an array as first argument to "%s" is deprecated. Use named arguments instead.', __METHOD__); | ||
} else { | ||
$localizedPaths = $data; | ||
$data = ['path' => $localizedPaths]; | ||
} | ||
} | ||
if (null !== $path && !\is_string($path) && !\is_array($path)) { | ||
throw new \TypeError(sprintf('"%s": Argument $path is expected to be a string, array or null, got "%s".', __METHOD__, get_debug_type($path))); | ||
} | ||
|
||
$data['path'] = $data['path'] ?? $path; | ||
$data['name'] = $data['name'] ?? $name; | ||
$data['requirements'] = $data['requirements'] ?? $requirements; | ||
$data['options'] = $data['options'] ?? $options; | ||
$data['defaults'] = $data['defaults'] ?? $defaults; | ||
$data['host'] = $data['host'] ?? $host; | ||
$data['methods'] = $data['methods'] ?? $methods; | ||
$data['schemes'] = $data['schemes'] ?? $schemes; | ||
$data['condition'] = $data['condition'] ?? $condition; | ||
$data['priority'] = $data['priority'] ?? $priority; | ||
$data['locale'] = $data['locale'] ?? $locale; | ||
$data['format'] = $data['format'] ?? $format; | ||
$data['utf8'] = $data['utf8'] ?? $utf8; | ||
$data['stateless'] = $data['stateless'] ?? $stateless; | ||
$data['env'] = $data['env'] ?? $env; | ||
|
||
$data = array_filter($data, static function ($value): bool { | ||
return null !== $value; | ||
}); | ||
|
||
if (isset($data['localized_paths'])) { | ||
throw new \BadMethodCallException(sprintf('Unknown property "localized_paths" on annotation "%s".', static::class)); | ||
} | ||
|
||
if (isset($data['value'])) { | ||
$data[\is_array($data['value']) ? 'localized_paths' : 'path'] = $data['value']; | ||
unset($data['value']); | ||
} | ||
|
||
if (isset($data['path']) && \is_array($data['path'])) { | ||
$data['localized_paths'] = $data['path']; | ||
unset($data['path']); | ||
} | ||
|
||
if (isset($data['locale'])) { | ||
$data['defaults']['_locale'] = $data['locale']; | ||
unset($data['locale']); | ||
if (\is_array($path)) { | ||
$this->localizedPaths = $path; | ||
} else { | ||
$this->path = $path; | ||
} | ||
$this->setMethods($methods); | ||
$this->setSchemes($schemes); | ||
|
||
if (isset($data['format'])) { | ||
$data['defaults']['_format'] = $data['format']; | ||
unset($data['format']); | ||
if (null !== $locale) { | ||
$this->defaults['_locale'] = $locale; | ||
} | ||
|
||
if (isset($data['utf8'])) { | ||
$data['options']['utf8'] = filter_var($data['utf8'], \FILTER_VALIDATE_BOOLEAN) ?: false; | ||
unset($data['utf8']); | ||
if (null !== $format) { | ||
$this->defaults['_format'] = $format; | ||
} | ||
|
||
if (isset($data['stateless'])) { | ||
$data['defaults']['_stateless'] = filter_var($data['stateless'], \FILTER_VALIDATE_BOOLEAN) ?: false; | ||
unset($data['stateless']); | ||
if (null !== $utf8) { | ||
$this->options['utf8'] = $utf8; | ||
} | ||
|
||
foreach ($data as $key => $value) { | ||
$method = 'set'.str_replace('_', '', $key); | ||
if (!method_exists($this, $method)) { | ||
throw new \BadMethodCallException(sprintf('Unknown property "%s" on annotation "%s".', $key, static::class)); | ||
} | ||
$this->$method($value); | ||
if (null !== $stateless) { | ||
$this->defaults['_stateless'] = $stateless; | ||
} | ||
} | ||
|
||
public function setPath($path) | ||
public function setPath(string $path) | ||
derrabus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->path = $path; | ||
} | ||
|
@@ -170,7 +96,7 @@ public function getLocalizedPaths(): array | |
return $this->localizedPaths; | ||
} | ||
|
||
public function setHost($pattern) | ||
public function setHost(string $pattern) | ||
{ | ||
$this->host = $pattern; | ||
} | ||
|
@@ -180,7 +106,7 @@ public function getHost() | |
return $this->host; | ||
} | ||
|
||
public function setName($name) | ||
public function setName(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
@@ -190,7 +116,7 @@ public function getName() | |
return $this->name; | ||
} | ||
|
||
public function setRequirements($requirements) | ||
public function setRequirements(array $requirements) | ||
{ | ||
$this->requirements = $requirements; | ||
} | ||
|
@@ -200,7 +126,7 @@ public function getRequirements() | |
return $this->requirements; | ||
} | ||
|
||
public function setOptions($options) | ||
public function setOptions(array $options) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
@@ -210,7 +136,7 @@ public function getOptions() | |
return $this->options; | ||
} | ||
|
||
public function setDefaults($defaults) | ||
public function setDefaults(array $defaults) | ||
{ | ||
$this->defaults = $defaults; | ||
} | ||
|
@@ -220,27 +146,27 @@ public function getDefaults() | |
return $this->defaults; | ||
} | ||
|
||
public function setSchemes($schemes) | ||
public function setSchemes(array | string $schemes) | ||
{ | ||
$this->schemes = \is_array($schemes) ? $schemes : [$schemes]; | ||
$this->schemes = (array) $schemes; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for a lower branch? |
||
} | ||
|
||
public function getSchemes() | ||
{ | ||
return $this->schemes; | ||
} | ||
|
||
public function setMethods($methods) | ||
public function setMethods(array | string $methods) | ||
{ | ||
$this->methods = \is_array($methods) ? $methods : [$methods]; | ||
$this->methods = (array) $methods; | ||
} | ||
|
||
public function getMethods() | ||
{ | ||
return $this->methods; | ||
} | ||
|
||
public function setCondition($condition) | ||
public function setCondition(?string $condition) | ||
{ | ||
$this->condition = $condition; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.