Augmentation vers version 3.3.0
This commit is contained in:
114
vendor/symfony/http-foundation/ParameterBag.php
vendored
114
vendor/symfony/http-foundation/ParameterBag.php
vendored
@@ -26,7 +26,7 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
/**
|
||||
* @param array $parameters An array of parameters
|
||||
*/
|
||||
public function __construct(array $parameters = array())
|
||||
public function __construct(array $parameters = [])
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*
|
||||
* @param array $parameters An array of parameters
|
||||
*/
|
||||
public function replace(array $parameters = array())
|
||||
public function replace(array $parameters = [])
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*
|
||||
* @param array $parameters An array of parameters
|
||||
*/
|
||||
public function add(array $parameters = array())
|
||||
public function add(array $parameters = [])
|
||||
{
|
||||
$this->parameters = array_replace($this->parameters, $parameters);
|
||||
}
|
||||
@@ -74,67 +74,14 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
/**
|
||||
* Returns a parameter by name.
|
||||
*
|
||||
* Note: Finding deep items is deprecated since version 2.8, to be removed in 3.0.
|
||||
*
|
||||
* @param string $key The key
|
||||
* @param mixed $default The default value if the parameter key does not exist
|
||||
* @param bool $deep If true, a path like foo[bar] will find deeper items
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function get($key, $default = null, $deep = false)
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
if ($deep) {
|
||||
@trigger_error('Using paths to find deeper items in '.__METHOD__.' is deprecated since Symfony 2.8 and will be removed in 3.0. Filter the returned value in your own code instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
if (!$deep || false === $pos = strpos($key, '[')) {
|
||||
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
|
||||
}
|
||||
|
||||
$root = substr($key, 0, $pos);
|
||||
if (!array_key_exists($root, $this->parameters)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$value = $this->parameters[$root];
|
||||
$currentKey = null;
|
||||
for ($i = $pos, $c = \strlen($key); $i < $c; ++$i) {
|
||||
$char = $key[$i];
|
||||
|
||||
if ('[' === $char) {
|
||||
if (null !== $currentKey) {
|
||||
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
|
||||
}
|
||||
|
||||
$currentKey = '';
|
||||
} elseif (']' === $char) {
|
||||
if (null === $currentKey) {
|
||||
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
|
||||
}
|
||||
|
||||
if (!\is_array($value) || !array_key_exists($currentKey, $value)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$value = $value[$currentKey];
|
||||
$currentKey = null;
|
||||
} else {
|
||||
if (null === $currentKey) {
|
||||
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
|
||||
}
|
||||
|
||||
$currentKey .= $char;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $currentKey) {
|
||||
throw new \InvalidArgumentException('Malformed path. Path must end with "]".');
|
||||
}
|
||||
|
||||
return $value;
|
||||
return \array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +104,7 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*/
|
||||
public function has($key)
|
||||
{
|
||||
return array_key_exists($key, $this->parameters);
|
||||
return \array_key_exists($key, $this->parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,13 +122,12 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*
|
||||
* @param string $key The parameter key
|
||||
* @param string $default The default value if the parameter key does not exist
|
||||
* @param bool $deep If true, a path like foo[bar] will find deeper items
|
||||
*
|
||||
* @return string The filtered value
|
||||
*/
|
||||
public function getAlpha($key, $default = '', $deep = false)
|
||||
public function getAlpha($key, $default = '')
|
||||
{
|
||||
return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
|
||||
return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,13 +135,12 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*
|
||||
* @param string $key The parameter key
|
||||
* @param string $default The default value if the parameter key does not exist
|
||||
* @param bool $deep If true, a path like foo[bar] will find deeper items
|
||||
*
|
||||
* @return string The filtered value
|
||||
*/
|
||||
public function getAlnum($key, $default = '', $deep = false)
|
||||
public function getAlnum($key, $default = '')
|
||||
{
|
||||
return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
|
||||
return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,14 +148,13 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*
|
||||
* @param string $key The parameter key
|
||||
* @param string $default The default value if the parameter key does not exist
|
||||
* @param bool $deep If true, a path like foo[bar] will find deeper items
|
||||
*
|
||||
* @return string The filtered value
|
||||
*/
|
||||
public function getDigits($key, $default = '', $deep = false)
|
||||
public function getDigits($key, $default = '')
|
||||
{
|
||||
// we need to remove - and + because they're allowed in the filter
|
||||
return str_replace(array('-', '+'), '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT, array(), $deep));
|
||||
return str_replace(['-', '+'], '', $this->filter($key, $default, FILTER_SANITIZE_NUMBER_INT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,13 +162,12 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*
|
||||
* @param string $key The parameter key
|
||||
* @param int $default The default value if the parameter key does not exist
|
||||
* @param bool $deep If true, a path like foo[bar] will find deeper items
|
||||
*
|
||||
* @return int The filtered value
|
||||
*/
|
||||
public function getInt($key, $default = 0, $deep = false)
|
||||
public function getInt($key, $default = 0)
|
||||
{
|
||||
return (int) $this->get($key, $default, $deep);
|
||||
return (int) $this->get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,13 +175,12 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
*
|
||||
* @param string $key The parameter key
|
||||
* @param bool $default The default value if the parameter key does not exist
|
||||
* @param bool $deep If true, a path like foo[bar] will find deeper items
|
||||
*
|
||||
* @return bool The filtered value
|
||||
*/
|
||||
public function getBoolean($key, $default = false, $deep = false)
|
||||
public function getBoolean($key, $default = false)
|
||||
{
|
||||
return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN, array(), $deep);
|
||||
return $this->filter($key, $default, FILTER_VALIDATE_BOOLEAN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,34 +190,18 @@ class ParameterBag implements \IteratorAggregate, \Countable
|
||||
* @param mixed $default Default = null
|
||||
* @param int $filter FILTER_* constant
|
||||
* @param mixed $options Filter options
|
||||
* @param bool $deep Default = false
|
||||
*
|
||||
* @see http://php.net/manual/en/function.filter-var.php
|
||||
* @see https://php.net/filter-var
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = array(), $deep = false)
|
||||
public function filter($key, $default = null, $filter = FILTER_DEFAULT, $options = [])
|
||||
{
|
||||
static $filters = null;
|
||||
|
||||
if (null === $filters) {
|
||||
foreach (filter_list() as $tmp) {
|
||||
$filters[filter_id($tmp)] = 1;
|
||||
}
|
||||
}
|
||||
if (\is_bool($filter) || !isset($filters[$filter]) || \is_array($deep)) {
|
||||
@trigger_error('Passing the $deep boolean as 3rd argument to the '.__METHOD__.' method is deprecated since Symfony 2.8 and will be removed in 3.0. Remove it altogether as the $deep argument will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
$tmp = $deep;
|
||||
$deep = $filter;
|
||||
$filter = $options;
|
||||
$options = $tmp;
|
||||
}
|
||||
|
||||
$value = $this->get($key, $default, $deep);
|
||||
$value = $this->get($key, $default);
|
||||
|
||||
// Always turn $options into an array - this allows filter_var option shortcuts.
|
||||
if (!\is_array($options) && $options) {
|
||||
$options = array('flags' => $options);
|
||||
$options = ['flags' => $options];
|
||||
}
|
||||
|
||||
// Add a convenience check for arrays.
|
||||
|
||||
Reference in New Issue
Block a user