'SERVER_NAME' => 'localhost',
'SERVER_PORT' => 80,
'HTTP_HOST' => 'localhost',
- 'HTTP_USER_AGENT' => 'Symfony/2.X',
+ 'HTTP_USER_AGENT' => 'Symfony/3.X',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
}
/**
- * Gets a "parameter" value.
+ * Gets a "parameter" value from any bag.
*
- * This method is mainly useful for libraries that want to provide some flexibility.
+ * This method is mainly useful for libraries that want to provide some flexibility. If you don't need the
+ * flexibility in controllers, it is better to explicitly get request parameters from the appropriate
+ * public property instead (attributes, query, request).
*
- * Order of precedence: GET, PATH, POST
- *
- * Avoid using this method in controllers:
- *
- * * slow
- * * prefer to get from a "named" source
- *
- * It is better to explicitly get request parameters from the appropriate
- * public property instead (query, attributes, request).
- *
- * Note: Finding deep items is deprecated since version 2.8, to be removed in 3.0.
+ * Order of precedence: PATH (routing placeholders or custom attributes), GET, BODY
*
* @param string $key the key
* @param mixed $default the default value if the parameter key does not exist
- * @param bool $deep is parameter deep in multidimensional array
*
* @return mixed
*/
- 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 version 2.8 and will be removed in 3.0. Filter the returned value in your own code instead.', E_USER_DEPRECATED);
- }
-
- if ($this !== $result = $this->query->get($key, $this, $deep)) {
+ if ($this !== $result = $this->attributes->get($key, $this)) {
return $result;
}
- if ($this !== $result = $this->attributes->get($key, $this, $deep)) {
+ if ($this !== $result = $this->query->get($key, $this)) {
return $result;
}
- if ($this !== $result = $this->request->get($key, $this, $deep)) {
+ if ($this !== $result = $this->request->get($key, $this)) {
return $result;
}
return isset(static::$formats[$format]) ? static::$formats[$format][0] : null;
}
+ /**
+ * Gets the mime types associated with the format.
+ *
+ * @param string $format The format
+ *
+ * @return array The associated mime types
+ */
+ public static function getMimeTypes($format)
+ {
+ if (null === static::$formats) {
+ static::initializeFormats();
+ }
+
+ return isset(static::$formats[$format]) ? static::$formats[$format] : array();
+ }
+
/**
* Gets the format associated with the mime type.
*
* Here is the process to determine the format:
*
* * format defined by the user (with setRequestFormat())
- * * _format request parameter
+ * * _format request attribute
* * $default
*
* @param string $default The default format
public function getRequestFormat($default = 'html')
{
if (null === $this->format) {
- $this->format = $this->get('_format');
+ $this->format = $this->attributes->get('_format');
}
return null === $this->format ? $default : $this->format;
}
/**
- * Checks whether the method is safe or not.
+ * Checks whether or not the method is safe.
*
* @see https://tools.ietf.org/html/rfc7231#section-4.2.1
*
*/
public function isMethodSafe(/* $andCacheable = true */)
{
- return in_array($this->getMethod(), 0 < func_num_args() && !func_get_arg(0) ? array('GET', 'HEAD', 'OPTIONS', 'TRACE') : array('GET', 'HEAD'));
+ if (!func_num_args() || func_get_arg(0)) {
+ // This deprecation should be turned into a BadMethodCallException in 4.0 (without adding the argument in the signature)
+ // then setting $andCacheable to false should be deprecated in 4.1
+ @trigger_error('Checking only for cacheable HTTP methods with Symfony\Component\HttpFoundation\Request::isMethodSafe() is deprecated since version 3.2 and will throw an exception in 4.0. Disable checking only for cacheable methods by calling the method with `false` as first argument or use the Request::isMethodCacheable() instead.', E_USER_DEPRECATED);
+
+ return in_array($this->getMethod(), array('GET', 'HEAD'));
+ }
+
+ return in_array($this->getMethod(), array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
+ }
+
+ /**
+ * Checks whether or not the method is idempotent.
+ *
+ * @return bool
+ */
+ public function isMethodIdempotent()
+ {
+ return in_array($this->getMethod(), array('HEAD', 'GET', 'PUT', 'DELETE', 'TRACE', 'OPTIONS', 'PURGE'));
}
/**
return new static($query, $request, $attributes, $cookies, $files, $server, $content);
}
- private function isFromTrustedProxy()
+ /**
+ * Indicates whether this request originated from a trusted proxy.
+ *
+ * This can be useful to determine whether or not to trust the
+ * contents of a proxy-specific header.
+ *
+ * @return bool true if the request came from a trusted proxy, false otherwise
+ */
+ public function isFromTrustedProxy()
{
return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
}