Skip to content

Commit

Permalink
Merge branch '3.4' into 4.2
Browse files Browse the repository at this point in the history
* 3.4: (24 commits)
  Apply php-cs-fixer rule for array_key_exists()
  [Security] Change FormAuthenticator if condition
  handles multi-byte characters in autocomplete
  speed up tests running them without debug flag
  [Translations] added missing Croatian validators
  Fix getItems() performance issue with RedisCluster (php-redis)
  [VarDumper] Keep a ref to objects to ensure their handle cannot be reused while cloning
  IntegerType: reject submitted non-integer numbers
  be keen to newcomers
  [HttpKernel] Fix possible infinite loop of exceptions
  fixed CS
  [Validator] Added missing translations for Afrikaans
  do not validate non-submitted form fields in PATCH requests
  Update usage example in ArrayInput doc block.
  [Console] Prevent ArgvInput::getFirstArgument() from returning an option value
  [Validator] Fixed duplicate UUID
  fixed CS
  [EventDispatcher] Fix unknown priority
  Avoid mutating the Finder when building the iterator
  [Validator] Add the missing translations for the Greek (el) locale
  ...
  • Loading branch information
nicolas-grekas committed Feb 23, 2019
2 parents 8d2318b + 9a96d77 commit 1de1944
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 20 deletions.
8 changes: 4 additions & 4 deletions HeaderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function get($key, $default = null, $first = true)
$key = str_replace('_', '-', strtolower($key));
$headers = $this->all();

if (!array_key_exists($key, $headers)) {
if (!\array_key_exists($key, $headers)) {
if (null === $default) {
return $first ? null : [];
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public function set($key, $values, $replace = true)
*/
public function has($key)
{
return array_key_exists(str_replace('_', '-', strtolower($key)), $this->all());
return \array_key_exists(str_replace('_', '-', strtolower($key)), $this->all());
}

/**
Expand Down Expand Up @@ -245,7 +245,7 @@ public function addCacheControlDirective($key, $value = true)
*/
public function hasCacheControlDirective($key)
{
return array_key_exists($key, $this->cacheControl);
return \array_key_exists($key, $this->cacheControl);
}

/**
Expand All @@ -257,7 +257,7 @@ public function hasCacheControlDirective($key)
*/
public function getCacheControlDirective($key)
{
return array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
return \array_key_exists($key, $this->cacheControl) ? $this->cacheControl[$key] : null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function add(array $parameters = [])
*/
public function get($key, $default = null)
{
return array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
return \array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
}

/**
Expand All @@ -104,7 +104,7 @@ public function set($key, $value)
*/
public function has($key)
{
return array_key_exists($key, $this->parameters);
return \array_key_exists($key, $this->parameters);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(?string $url, int $status = 302, array $headers = []
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
}

if (301 == $status && !array_key_exists('cache-control', $headers)) {
if (301 == $status && !\array_key_exists('cache-control', $headers)) {
$this->headers->remove('cache-control');
}
}
Expand Down
75 changes: 75 additions & 0 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,81 @@ public static function getTrustedHosts()
}

/**
<<<<<<< HEAD
=======
* Sets the name for trusted headers.
*
* The following header keys are supported:
*
* * Request::HEADER_CLIENT_IP: defaults to X-Forwarded-For (see getClientIp())
* * Request::HEADER_CLIENT_HOST: defaults to X-Forwarded-Host (see getHost())
* * Request::HEADER_CLIENT_PORT: defaults to X-Forwarded-Port (see getPort())
* * Request::HEADER_CLIENT_PROTO: defaults to X-Forwarded-Proto (see getScheme() and isSecure())
* * Request::HEADER_FORWARDED: defaults to Forwarded (see RFC 7239)
*
* Setting an empty value allows to disable the trusted header for the given key.
*
* @param string $key The header key
* @param string $value The header name
*
* @throws \InvalidArgumentException
*
* @deprecated since version 3.3, to be removed in 4.0. Use the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.
*/
public static function setTrustedHeaderName($key, $value)
{
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the $trustedHeaderSet argument of the Request::setTrustedProxies() method instead.', __METHOD__), E_USER_DEPRECATED);

if ('forwarded' === $key) {
$key = self::HEADER_FORWARDED;
} elseif ('client_ip' === $key) {
$key = self::HEADER_CLIENT_IP;
} elseif ('client_host' === $key) {
$key = self::HEADER_CLIENT_HOST;
} elseif ('client_proto' === $key) {
$key = self::HEADER_CLIENT_PROTO;
} elseif ('client_port' === $key) {
$key = self::HEADER_CLIENT_PORT;
} elseif (!\array_key_exists($key, self::$trustedHeaders)) {
throw new \InvalidArgumentException(sprintf('Unable to set the trusted header name for key "%s".', $key));
}

self::$trustedHeaders[$key] = $value;

if (null !== $value) {
self::$trustedHeaderNames[$key] = $value;
self::$trustedHeaderSet |= $key;
} else {
self::$trustedHeaderSet &= ~$key;
}
}

/**
* Gets the trusted proxy header name.
*
* @param string $key The header key
*
* @return string The header name
*
* @throws \InvalidArgumentException
*
* @deprecated since version 3.3, to be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.
*/
public static function getTrustedHeaderName($key)
{
if (2 > \func_num_args() || func_get_arg(1)) {
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 3.3 and will be removed in 4.0. Use the Request::getTrustedHeaderSet() method instead.', __METHOD__), E_USER_DEPRECATED);
}

if (!\array_key_exists($key, self::$trustedHeaders)) {
throw new \InvalidArgumentException(sprintf('Unable to get the trusted header name for key "%s".', $key));
}

return self::$trustedHeaders[$key];
}

/**
>>>>>>> 3.4
* Normalizes a query string.
*
* It builds a normalized query string, where keys/value pairs are alphabetized,
Expand Down
4 changes: 2 additions & 2 deletions ResponseHeaderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ public function remove($key)
*/
public function hasCacheControlDirective($key)
{
return array_key_exists($key, $this->computedCacheControl);
return \array_key_exists($key, $this->computedCacheControl);
}

/**
* {@inheritdoc}
*/
public function getCacheControlDirective($key)
{
return array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
return \array_key_exists($key, $this->computedCacheControl) ? $this->computedCacheControl[$key] : null;
}

public function setCookie(Cookie $cookie)
Expand Down
6 changes: 3 additions & 3 deletions Session/Attribute/AttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public function getStorageKey()
*/
public function has($name)
{
return array_key_exists($name, $this->attributes);
return \array_key_exists($name, $this->attributes);
}

/**
* {@inheritdoc}
*/
public function get($name, $default = null)
{
return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : $default;
}

/**
Expand Down Expand Up @@ -107,7 +107,7 @@ public function replace(array $attributes)
public function remove($name)
{
$retval = null;
if (array_key_exists($name, $this->attributes)) {
if (\array_key_exists($name, $this->attributes)) {
$retval = $this->attributes[$name];
unset($this->attributes[$name]);
}
Expand Down
8 changes: 4 additions & 4 deletions Session/Attribute/NamespacedAttributeBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function has($name)
return false;
}

return array_key_exists($name, $attributes);
return \array_key_exists($name, $attributes);
}

/**
Expand All @@ -60,7 +60,7 @@ public function get($name, $default = null)
return $default;
}

return array_key_exists($name, $attributes) ? $attributes[$name] : $default;
return \array_key_exists($name, $attributes) ? $attributes[$name] : $default;
}

/**
Expand All @@ -81,7 +81,7 @@ public function remove($name)
$retval = null;
$attributes = &$this->resolveAttributePath($name);
$name = $this->resolveKey($name);
if (null !== $attributes && array_key_exists($name, $attributes)) {
if (null !== $attributes && \array_key_exists($name, $attributes)) {
$retval = $attributes[$name];
unset($attributes[$name]);
}
Expand Down Expand Up @@ -123,7 +123,7 @@ protected function &resolveAttributePath($name, $writeContext = false)
unset($parts[\count($parts) - 1]);

foreach ($parts as $part) {
if (null !== $array && !array_key_exists($part, $array)) {
if (null !== $array && !\array_key_exists($part, $array)) {
if (!$writeContext) {
$null = null;

Expand Down
6 changes: 3 additions & 3 deletions Session/Flash/AutoExpireFlashBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function initialize(array &$flashes)
// The logic: messages from the last request will be stored in new, so we move them to previous
// This request we will show what is in 'display'. What is placed into 'new' this time round will
// be moved to display next time round.
$this->flashes['display'] = array_key_exists('new', $this->flashes) ? $this->flashes['new'] : [];
$this->flashes['display'] = \array_key_exists('new', $this->flashes) ? $this->flashes['new'] : [];
$this->flashes['new'] = [];
}

Expand All @@ -78,7 +78,7 @@ public function peek($type, array $default = [])
*/
public function peekAll()
{
return array_key_exists('display', $this->flashes) ? (array) $this->flashes['display'] : [];
return \array_key_exists('display', $this->flashes) ? (array) $this->flashes['display'] : [];
}

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ public function set($type, $messages)
*/
public function has($type)
{
return array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
return \array_key_exists($type, $this->flashes['display']) && $this->flashes['display'][$type];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Session/Flash/FlashBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function setAll(array $messages)
*/
public function has($type)
{
return array_key_exists($type, $this->flashes) && $this->flashes[$type];
return \array_key_exists($type, $this->flashes) && $this->flashes[$type];
}

/**
Expand Down

0 comments on commit 1de1944

Please sign in to comment.