updated-packages
This commit is contained in:
164
vendor/symfony/routing/Route.php
vendored
164
vendor/symfony/routing/Route.php
vendored
@@ -21,11 +21,11 @@ class Route implements \Serializable
|
||||
{
|
||||
private $path = '/';
|
||||
private $host = '';
|
||||
private $schemes = array();
|
||||
private $methods = array();
|
||||
private $defaults = array();
|
||||
private $requirements = array();
|
||||
private $options = array();
|
||||
private $schemes = [];
|
||||
private $methods = [];
|
||||
private $defaults = [];
|
||||
private $requirements = [];
|
||||
private $options = [];
|
||||
private $condition = '';
|
||||
|
||||
/**
|
||||
@@ -45,12 +45,12 @@ class Route implements \Serializable
|
||||
* @param array $defaults An array of default parameter values
|
||||
* @param array $requirements An array of requirements for parameters (regexes)
|
||||
* @param array $options An array of options
|
||||
* @param string $host The host pattern to match
|
||||
* @param string|null $host The host pattern to match
|
||||
* @param string|string[] $schemes A required URI scheme or an array of restricted schemes
|
||||
* @param string|string[] $methods A required HTTP method or an array of restricted methods
|
||||
* @param string $condition A condition that should evaluate to true for the route to match
|
||||
* @param string|null $condition A condition that should evaluate to true for the route to match
|
||||
*/
|
||||
public function __construct(string $path, array $defaults = array(), array $requirements = array(), array $options = array(), ?string $host = '', $schemes = array(), $methods = array(), ?string $condition = '')
|
||||
public function __construct(string $path, array $defaults = [], array $requirements = [], array $options = [], ?string $host = '', $schemes = [], $methods = [], ?string $condition = '')
|
||||
{
|
||||
$this->setPath($path);
|
||||
$this->addDefaults($defaults);
|
||||
@@ -62,12 +62,9 @@ class Route implements \Serializable
|
||||
$this->setCondition($condition);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function serialize()
|
||||
public function __serialize(): array
|
||||
{
|
||||
return serialize(array(
|
||||
return [
|
||||
'path' => $this->path,
|
||||
'host' => $this->host,
|
||||
'defaults' => $this->defaults,
|
||||
@@ -77,15 +74,22 @@ class Route implements \Serializable
|
||||
'methods' => $this->methods,
|
||||
'condition' => $this->condition,
|
||||
'compiled' => $this->compiled,
|
||||
));
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return string
|
||||
*
|
||||
* @internal since Symfony 4.3
|
||||
* @final since Symfony 4.3
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
public function serialize()
|
||||
{
|
||||
return serialize($this->__serialize());
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
$data = unserialize($serialized);
|
||||
$this->path = $data['path'];
|
||||
$this->host = $data['host'];
|
||||
$this->defaults = $data['defaults'];
|
||||
@@ -103,8 +107,15 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern for the path.
|
||||
*
|
||||
* @internal since Symfony 4.3
|
||||
* @final since Symfony 4.3
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$this->__unserialize(unserialize($serialized));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string The path pattern
|
||||
*/
|
||||
public function getPath()
|
||||
@@ -115,8 +126,6 @@ class Route implements \Serializable
|
||||
/**
|
||||
* Sets the pattern for the path.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $pattern The path pattern
|
||||
*
|
||||
* @return $this
|
||||
@@ -124,15 +133,15 @@ class Route implements \Serializable
|
||||
public function setPath($pattern)
|
||||
{
|
||||
if (false !== strpbrk($pattern, '?<')) {
|
||||
$pattern = preg_replace_callback('#\{(\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
|
||||
if (isset($m[3][0])) {
|
||||
$this->setDefault($m[1], '?' !== $m[3] ? substr($m[3], 1) : null);
|
||||
$pattern = preg_replace_callback('#\{(!?)(\w++)(<.*?>)?(\?[^\}]*+)?\}#', function ($m) {
|
||||
if (isset($m[4][0])) {
|
||||
$this->setDefault($m[2], '?' !== $m[4] ? substr($m[4], 1) : null);
|
||||
}
|
||||
if (isset($m[2][0])) {
|
||||
$this->setRequirement($m[1], substr($m[2], 1, -1));
|
||||
if (isset($m[3][0])) {
|
||||
$this->setRequirement($m[2], substr($m[3], 1, -1));
|
||||
}
|
||||
|
||||
return '{'.$m[1].'}';
|
||||
return '{'.$m[1].$m[2].'}';
|
||||
}, $pattern);
|
||||
}
|
||||
|
||||
@@ -145,8 +154,6 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern for the host.
|
||||
*
|
||||
* @return string The host pattern
|
||||
*/
|
||||
public function getHost()
|
||||
@@ -157,8 +164,6 @@ class Route implements \Serializable
|
||||
/**
|
||||
* Sets the pattern for the host.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $pattern The host pattern
|
||||
*
|
||||
* @return $this
|
||||
@@ -186,8 +191,6 @@ class Route implements \Serializable
|
||||
* Sets the schemes (e.g. 'https') this route is restricted to.
|
||||
* So an empty array means that any scheme is allowed.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string|string[] $schemes The scheme or an array of schemes
|
||||
*
|
||||
* @return $this
|
||||
@@ -227,8 +230,6 @@ class Route implements \Serializable
|
||||
* Sets the HTTP methods (e.g. 'POST') this route is restricted to.
|
||||
* So an empty array means that any method is allowed.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string|string[] $methods The method or an array of methods
|
||||
*
|
||||
* @return $this
|
||||
@@ -242,8 +243,6 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options.
|
||||
*
|
||||
* @return array The options
|
||||
*/
|
||||
public function getOptions()
|
||||
@@ -252,30 +251,18 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the options.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->options = array(
|
||||
$this->options = [
|
||||
'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
|
||||
);
|
||||
];
|
||||
|
||||
return $this->addOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds options.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $options The options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addOptions(array $options)
|
||||
@@ -291,8 +278,6 @@ class Route implements \Serializable
|
||||
/**
|
||||
* Sets an option value.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $name An option name
|
||||
* @param mixed $value The option value
|
||||
*
|
||||
@@ -315,7 +300,7 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function getOption($name)
|
||||
{
|
||||
return isset($this->options[$name]) ? $this->options[$name] : null;
|
||||
return $this->options[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,12 +312,10 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function hasOption($name)
|
||||
{
|
||||
return array_key_exists($name, $this->options);
|
||||
return \array_key_exists($name, $this->options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the defaults.
|
||||
*
|
||||
* @return array The defaults
|
||||
*/
|
||||
public function getDefaults()
|
||||
@@ -341,32 +324,24 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the defaults.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $defaults The defaults
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDefaults(array $defaults)
|
||||
{
|
||||
$this->defaults = array();
|
||||
$this->defaults = [];
|
||||
|
||||
return $this->addDefaults($defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds defaults.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $defaults The defaults
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addDefaults(array $defaults)
|
||||
{
|
||||
if (isset($defaults['_locale']) && $this->isLocalized()) {
|
||||
unset($defaults['_locale']);
|
||||
}
|
||||
|
||||
foreach ($defaults as $name => $default) {
|
||||
$this->defaults[$name] = $default;
|
||||
}
|
||||
@@ -384,7 +359,7 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function getDefault($name)
|
||||
{
|
||||
return isset($this->defaults[$name]) ? $this->defaults[$name] : null;
|
||||
return $this->defaults[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,7 +371,7 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function hasDefault($name)
|
||||
{
|
||||
return array_key_exists($name, $this->defaults);
|
||||
return \array_key_exists($name, $this->defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,6 +384,10 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function setDefault($name, $default)
|
||||
{
|
||||
if ('_locale' === $name && $this->isLocalized()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->defaults[$name] = $default;
|
||||
$this->compiled = null;
|
||||
|
||||
@@ -416,8 +395,6 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the requirements.
|
||||
*
|
||||
* @return array The requirements
|
||||
*/
|
||||
public function getRequirements()
|
||||
@@ -426,32 +403,24 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the requirements.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $requirements The requirements
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRequirements(array $requirements)
|
||||
{
|
||||
$this->requirements = array();
|
||||
$this->requirements = [];
|
||||
|
||||
return $this->addRequirements($requirements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds requirements.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param array $requirements The requirements
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addRequirements(array $requirements)
|
||||
{
|
||||
if (isset($requirements['_locale']) && $this->isLocalized()) {
|
||||
unset($requirements['_locale']);
|
||||
}
|
||||
|
||||
foreach ($requirements as $key => $regex) {
|
||||
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
|
||||
}
|
||||
@@ -469,7 +438,7 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function getRequirement($key)
|
||||
{
|
||||
return isset($this->requirements[$key]) ? $this->requirements[$key] : null;
|
||||
return $this->requirements[$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -481,7 +450,7 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function hasRequirement($key)
|
||||
{
|
||||
return array_key_exists($key, $this->requirements);
|
||||
return \array_key_exists($key, $this->requirements);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,6 +463,10 @@ class Route implements \Serializable
|
||||
*/
|
||||
public function setRequirement($key, $regex)
|
||||
{
|
||||
if ('_locale' === $key && $this->isLocalized()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
|
||||
$this->compiled = null;
|
||||
|
||||
@@ -501,8 +474,6 @@ class Route implements \Serializable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the condition.
|
||||
*
|
||||
* @return string The condition
|
||||
*/
|
||||
public function getCondition()
|
||||
@@ -513,8 +484,6 @@ class Route implements \Serializable
|
||||
/**
|
||||
* Sets the condition.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $condition The condition
|
||||
*
|
||||
* @return $this
|
||||
@@ -548,7 +517,7 @@ class Route implements \Serializable
|
||||
return $this->compiled = $class::compile($this);
|
||||
}
|
||||
|
||||
private function sanitizeRequirement($key, $regex)
|
||||
private function sanitizeRequirement(string $key, $regex)
|
||||
{
|
||||
if (!\is_string($regex)) {
|
||||
throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string.', $key));
|
||||
@@ -558,7 +527,7 @@ class Route implements \Serializable
|
||||
$regex = (string) substr($regex, 1); // returns false for a single character
|
||||
}
|
||||
|
||||
if ('$' === substr($regex, -1)) {
|
||||
if (str_ends_with($regex, '$')) {
|
||||
$regex = substr($regex, 0, -1);
|
||||
}
|
||||
|
||||
@@ -568,4 +537,9 @@ class Route implements \Serializable
|
||||
|
||||
return $regex;
|
||||
}
|
||||
|
||||
private function isLocalized(): bool
|
||||
{
|
||||
return isset($this->defaults['_locale']) && isset($this->defaults['_canonical_route']) && ($this->requirements['_locale'] ?? null) === preg_quote($this->defaults['_locale'], RouteCompiler::REGEX_DELIMITER);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user