Update to laravel 7

This commit is contained in:
KodeStar
2022-03-10 11:54:29 +00:00
parent 61a5a1a8b0
commit f9a19fce91
7170 changed files with 274189 additions and 283773 deletions

View File

@@ -45,10 +45,10 @@ 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 $requirements = [], array $options = [], ?string $host = '', $schemes = [], $methods = [], ?string $condition = '')
{
@@ -78,10 +78,9 @@ class Route implements \Serializable
}
/**
* @internal since Symfony 4.3
* @final since Symfony 4.3
* @internal
*/
public function serialize()
final public function serialize(): string
{
return serialize($this->__serialize());
}
@@ -105,18 +104,15 @@ class Route implements \Serializable
}
/**
* @internal since Symfony 4.3
* @final since Symfony 4.3
* @internal
*/
public function unserialize($serialized)
final public function unserialize($serialized)
{
$this->__unserialize(unserialize($serialized));
}
/**
* Returns the pattern for the path.
*
* @return string The path pattern
* @return string
*/
public function getPath()
{
@@ -124,28 +120,11 @@ class Route implements \Serializable
}
/**
* Sets the pattern for the path.
*
* This method implements a fluent interface.
*
* @param string $pattern The path pattern
*
* @return $this
*/
public function setPath($pattern)
public function setPath(string $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);
}
if (isset($m[2][0])) {
$this->setRequirement($m[1], substr($m[2], 1, -1));
}
return '{'.$m[1].'}';
}, $pattern);
}
$pattern = $this->extractInlineDefaultsAndRequirements($pattern);
// A pattern must start with a slash and must not have multiple slashes at the beginning because the
// generated path for this route would be confused with a network path, e.g. '//domain.com/path'.
@@ -156,9 +135,7 @@ class Route implements \Serializable
}
/**
* Returns the pattern for the host.
*
* @return string The host pattern
* @return string
*/
public function getHost()
{
@@ -166,17 +143,11 @@ class Route implements \Serializable
}
/**
* Sets the pattern for the host.
*
* This method implements a fluent interface.
*
* @param string $pattern The host pattern
*
* @return $this
*/
public function setHost($pattern)
public function setHost(?string $pattern)
{
$this->host = (string) $pattern;
$this->host = $this->extractInlineDefaultsAndRequirements((string) $pattern);
$this->compiled = null;
return $this;
@@ -186,7 +157,7 @@ class Route implements \Serializable
* Returns the lowercased schemes this route is restricted to.
* So an empty array means that any scheme is allowed.
*
* @return string[] The schemes
* @return string[]
*/
public function getSchemes()
{
@@ -197,8 +168,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
@@ -214,11 +183,9 @@ class Route implements \Serializable
/**
* Checks if a scheme requirement has been set.
*
* @param string $scheme
*
* @return bool true if the scheme requirement exists, otherwise false
* @return bool
*/
public function hasScheme($scheme)
public function hasScheme(string $scheme)
{
return \in_array(strtolower($scheme), $this->schemes, true);
}
@@ -227,7 +194,7 @@ class Route implements \Serializable
* Returns the uppercased HTTP methods this route is restricted to.
* So an empty array means that any method is allowed.
*
* @return string[] The methods
* @return string[]
*/
public function getMethods()
{
@@ -238,8 +205,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
@@ -253,9 +218,7 @@ class Route implements \Serializable
}
/**
* Returns the options.
*
* @return array The options
* @return array
*/
public function getOptions()
{
@@ -263,12 +226,6 @@ 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)
@@ -281,12 +238,6 @@ class Route implements \Serializable
}
/**
* Adds options.
*
* This method implements a fluent interface.
*
* @param array $options The options
*
* @return $this
*/
public function addOptions(array $options)
@@ -302,14 +253,11 @@ 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
* @param mixed $value The option value
*
* @return $this
*/
public function setOption($name, $value)
public function setOption(string $name, $value)
{
$this->options[$name] = $value;
$this->compiled = null;
@@ -318,33 +266,25 @@ class Route implements \Serializable
}
/**
* Get an option value.
* Returns the option value or null when not found.
*
* @param string $name An option name
*
* @return mixed The option value or null when not given
* @return mixed
*/
public function getOption($name)
public function getOption(string $name)
{
return isset($this->options[$name]) ? $this->options[$name] : null;
return $this->options[$name] ?? null;
}
/**
* Checks if an option has been set.
*
* @param string $name An option name
*
* @return bool true if the option is set, false otherwise
* @return bool
*/
public function hasOption($name)
public function hasOption(string $name)
{
return \array_key_exists($name, $this->options);
}
/**
* Returns the defaults.
*
* @return array The defaults
* @return array
*/
public function getDefaults()
{
@@ -352,12 +292,6 @@ 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)
@@ -368,16 +302,14 @@ class Route implements \Serializable
}
/**
* 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;
}
@@ -387,25 +319,17 @@ class Route implements \Serializable
}
/**
* Gets a default value.
*
* @param string $name A variable name
*
* @return mixed The default value or null when not given
* @return mixed
*/
public function getDefault($name)
public function getDefault(string $name)
{
return isset($this->defaults[$name]) ? $this->defaults[$name] : null;
return $this->defaults[$name] ?? null;
}
/**
* Checks if a default value is set for the given variable.
*
* @param string $name A variable name
*
* @return bool true if the default value is set, false otherwise
* @return bool
*/
public function hasDefault($name)
public function hasDefault(string $name)
{
return \array_key_exists($name, $this->defaults);
}
@@ -413,13 +337,16 @@ class Route implements \Serializable
/**
* Sets a default value.
*
* @param string $name A variable name
* @param mixed $default The default value
* @param mixed $default The default value
*
* @return $this
*/
public function setDefault($name, $default)
public function setDefault(string $name, $default)
{
if ('_locale' === $name && $this->isLocalized()) {
return $this;
}
$this->defaults[$name] = $default;
$this->compiled = null;
@@ -427,9 +354,7 @@ class Route implements \Serializable
}
/**
* Returns the requirements.
*
* @return array The requirements
* @return array
*/
public function getRequirements()
{
@@ -437,12 +362,6 @@ 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)
@@ -453,16 +372,14 @@ class Route implements \Serializable
}
/**
* 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);
}
@@ -472,39 +389,30 @@ class Route implements \Serializable
}
/**
* Returns the requirement for the given key.
*
* @param string $key The key
*
* @return string|null The regex or null when not given
* @return string|null
*/
public function getRequirement($key)
public function getRequirement(string $key)
{
return isset($this->requirements[$key]) ? $this->requirements[$key] : null;
return $this->requirements[$key] ?? null;
}
/**
* Checks if a requirement is set for the given key.
*
* @param string $key A variable name
*
* @return bool true if a requirement is specified, false otherwise
* @return bool
*/
public function hasRequirement($key)
public function hasRequirement(string $key)
{
return \array_key_exists($key, $this->requirements);
}
/**
* Sets a requirement for the given key.
*
* @param string $key The key
* @param string $regex The regex
*
* @return $this
*/
public function setRequirement($key, $regex)
public function setRequirement(string $key, string $regex)
{
if ('_locale' === $key && $this->isLocalized()) {
return $this;
}
$this->requirements[$key] = $this->sanitizeRequirement($key, $regex);
$this->compiled = null;
@@ -512,9 +420,7 @@ class Route implements \Serializable
}
/**
* Returns the condition.
*
* @return string The condition
* @return string
*/
public function getCondition()
{
@@ -522,15 +428,9 @@ class Route implements \Serializable
}
/**
* Sets the condition.
*
* This method implements a fluent interface.
*
* @param string $condition The condition
*
* @return $this
*/
public function setCondition($condition)
public function setCondition(?string $condition)
{
$this->condition = (string) $condition;
$this->compiled = null;
@@ -541,7 +441,7 @@ class Route implements \Serializable
/**
* Compiles the route.
*
* @return CompiledRoute A CompiledRoute instance
* @return CompiledRoute
*
* @throws \LogicException If the Route cannot be compiled because the
* path or host pattern is invalid
@@ -559,18 +459,38 @@ class Route implements \Serializable
return $this->compiled = $class::compile($this);
}
private function sanitizeRequirement($key, $regex)
private function extractInlineDefaultsAndRequirements(string $pattern): string
{
if (!\is_string($regex)) {
throw new \InvalidArgumentException(sprintf('Routing requirement for "%s" must be a string.', $key));
if (false === strpbrk($pattern, '?<')) {
return $pattern;
}
if ('' !== $regex && '^' === $regex[0]) {
$regex = (string) substr($regex, 1); // returns false for a single character
return 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[3][0])) {
$this->setRequirement($m[2], substr($m[3], 1, -1));
}
return '{'.$m[1].$m[2].'}';
}, $pattern);
}
private function sanitizeRequirement(string $key, string $regex)
{
if ('' !== $regex) {
if ('^' === $regex[0]) {
$regex = substr($regex, 1);
} elseif (0 === strpos($regex, '\\A')) {
$regex = substr($regex, 2);
}
}
if ('$' === substr($regex, -1)) {
if (str_ends_with($regex, '$')) {
$regex = substr($regex, 0, -1);
} elseif (\strlen($regex) - 2 === strpos($regex, '\\z')) {
$regex = substr($regex, 0, -2);
}
if ('' === $regex) {
@@ -579,4 +499,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']);
}
}