Commit 87e5ffc3 authored by Dries's avatar Dries

- Patch #1343160 by msonnabaum: update Symfony2 components to latest release.

parent b956b400
......@@ -17,7 +17,7 @@
* It is able to load classes that use either:
*
* * The technical interoperability standards for PHP 5.3 namespaces and
* class names (http://groups.google.com/group/php-standards/web/psr-0-final-proposal);
* class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md);
*
* * The PEAR naming convention for classes (http://pear.php.net/).
*
......
......@@ -17,7 +17,7 @@
* It is able to load classes that use either:
*
* * The technical interoperability standards for PHP 5.3 namespaces and
* class names (http://groups.google.com/group/php-standards/web/psr-0-final-proposal);
* class names (https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md);
*
* * The PEAR naming convention for classes (http://pear.php.net/).
*
......
......@@ -4,7 +4,6 @@
"description": "Symfony ClassLoader Component",
"keywords": [],
"homepage": "http://symfony.com",
"version": "2.0.4",
"license": "MIT",
"authors": [
{
......@@ -18,5 +17,9 @@
],
"require": {
"php": ">=5.3.2"
}
},
"autoload": {
"psr-0": { "Symfony\\Component\\ClassLoader": "" }
},
"target-dir": "Symfony/Component/ClassLoader"
}
......@@ -46,6 +46,6 @@ protected function prepareBaseUrl()
*/
protected function preparePathInfo()
{
return $this->server->get('PATH_INFO');
return $this->server->get('PATH_INFO') ?: substr($this->prepareRequestUri(), strlen($this->prepareBaseUrl())) ?: '/';
}
}
......@@ -48,10 +48,6 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
}
if (preg_match("/[,; \t\r\n\013\014]/", $value)) {
throw new \InvalidArgumentException(sprintf('The cookie value "%s" contains invalid characters.', $value));
}
if (empty($name)) {
throw new \InvalidArgumentException('The cookie name cannot be empty.');
}
......
......@@ -428,6 +428,7 @@ class File extends \SplFileInfo
'video/vnd.sealedmedia.softseal.mov' => 'smov',
'video/vnd.vivo' => 'vivo',
'video/x-fli' => 'fli',
'video/x-flv' => 'flv',
'video/x-ms-asf' => 'asf',
'video/x-ms-wmv' => 'wmv',
'video/x-msvideo' => 'avi',
......@@ -445,15 +446,16 @@ class File extends \SplFileInfo
/**
* Constructs a new file from the given path.
*
* @param string $path The path to the file
* @param string $path The path to the file
* @param Boolean $checkPath Whether to check the path or not
*
* @throws FileNotFoundException If the given path is not a file
*
* @api
*/
public function __construct($path)
public function __construct($path, $checkPath = true)
{
if (!is_file($path)) {
if ($checkPath && !is_file($path)) {
throw new FileNotFoundException($path);
}
......
......@@ -97,7 +97,9 @@ public function register(MimeTypeGuesserInterface $guesser)
* value.
*
* @param string $path The path to the file
*
* @return string The mime type or NULL, if none could be guessed
*
* @throws FileException If the file does not exist
*/
public function guess($path)
......@@ -110,16 +112,14 @@ public function guess($path)
throw new AccessDeniedException($path);
}
$mimeType = null;
if (!$this->guessers) {
throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)');
}
foreach ($this->guessers as $guesser) {
$mimeType = $guesser->guess($path);
if (null !== $mimeType) {
break;
if (null !== $mimeType = $guesser->guess($path)) {
return $mimeType;
}
}
return $mimeType;
}
}
......@@ -19,10 +19,12 @@
interface MimeTypeGuesserInterface
{
/**
* Guesses the mime type of the file with the given path
* Guesses the mime type of the file with the given path.
*
* @param string $path The path to the file
*
* @return string The mime type or NULL, if none could be guessed
*
* @throws FileNotFoundException If the file does not exist
* @throws AccessDeniedException If the file could not be read
*/
......
......@@ -100,9 +100,7 @@ public function __construct($path, $originalName, $mimeType = null, $size = null
$this->error = $error ?: UPLOAD_ERR_OK;
$this->test = (Boolean) $test;
if (UPLOAD_ERR_OK === $this->error) {
parent::__construct($path);
}
parent::__construct($path, UPLOAD_ERR_OK === $this->error);
}
/**
......
......@@ -122,6 +122,7 @@ protected function convertFileInformation($file)
* just returns the original array unmodified.
*
* @param array $data
*
* @return array
*/
protected function fixPhpFilesArray($data)
......
......@@ -86,8 +86,8 @@ public function add(array $parameters = array())
* Returns a parameter by name.
*
* @param string $path The key
* @param mixed $default The default value
* @param boolean $deep
* @param mixed $default The default value if the parameter key does not exist
* @param boolean $deep If true, a path like foo[bar] will find deeper items
*
* @api
*/
......@@ -113,7 +113,7 @@ public function get($path, $default = null, $deep = false)
}
$currentKey = '';
} else if (']' === $char) {
} elseif (']' === $char) {
if (null === $currentKey) {
throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
}
......@@ -183,8 +183,8 @@ public function remove($key)
* Returns the alphabetic characters of the parameter value.
*
* @param string $key The parameter key
* @param mixed $default The default value
* @param boolean $deep
* @param mixed $default The default value if the parameter key does not exist
* @param boolean $deep If true, a path like foo[bar] will find deeper items
*
* @return string The filtered value
*
......@@ -199,8 +199,8 @@ public function getAlpha($key, $default = '', $deep = false)
* Returns the alphabetic characters and digits of the parameter value.
*
* @param string $key The parameter key
* @param mixed $default The default value
* @param boolean $deep
* @param mixed $default The default value if the parameter key does not exist
* @param boolean $deep If true, a path like foo[bar] will find deeper items
*
* @return string The filtered value
*
......@@ -215,8 +215,8 @@ public function getAlnum($key, $default = '', $deep = false)
* Returns the digits of the parameter value.
*
* @param string $key The parameter key
* @param mixed $default The default value
* @param boolean $deep
* @param mixed $default The default value if the parameter key does not exist
* @param boolean $deep If true, a path like foo[bar] will find deeper items
*
* @return string The filtered value
*
......@@ -231,8 +231,8 @@ public function getDigits($key, $default = '', $deep = false)
* Returns the parameter value converted to integer.
*
* @param string $key The parameter key
* @param mixed $default The default value
* @param boolean $deep
* @param mixed $default The default value if the parameter key does not exist
* @param boolean $deep If true, a path like foo[bar] will find deeper items
*
* @return string The filtered value
*
......
......@@ -453,7 +453,9 @@ public function getClientIp($proxy = false)
if ($this->server->has('HTTP_CLIENT_IP')) {
return $this->server->get('HTTP_CLIENT_IP');
} elseif (self::$trustProxy && $this->server->has('HTTP_X_FORWARDED_FOR')) {
return $this->server->get('HTTP_X_FORWARDED_FOR');
$clientIp = explode(',', $this->server->get('HTTP_X_FORWARDED_FOR'), 2);
return isset($clientIp[0]) ? trim($clientIp[0]) : '';
}
}
......@@ -560,7 +562,11 @@ public function getScheme()
*/
public function getPort()
{
return $this->headers->get('X-Forwarded-Port') ?: $this->server->get('SERVER_PORT');
if (self::$trustProxy && $this->headers->has('X-Forwarded-Port')) {
return $this->headers->get('X-Forwarded-Port');
} else {
return $this->server->get('SERVER_PORT');
}
}
/**
......@@ -639,7 +645,7 @@ public function getUriForPath($path)
* It builds a normalized query string, where keys/value pairs are alphabetized
* and have consistent escaping.
*
* @return string A normalized query string for the Request
* @return string|null A normalized query string for the Request
*
* @api
*/
......@@ -845,6 +851,24 @@ public function setRequestFormat($format)
$this->format = $format;
}
public function setLocale($locale)
{
if (!$this->hasSession()) {
throw new \LogicException('Forward compatibility for Request::setLocale() requires the session to be set.');
}
$this->session->setLocale($locale);
}
public function getLocale()
{
if (!$this->hasSession()) {
throw new \LogicException('Forward compatibility for Request::getLocale() requires the session to be set.');
}
return $this->session->getLocale();
}
/**
* Checks whether the method is safe or not.
*
......@@ -903,7 +927,7 @@ public function isNoCache()
*
* @param array $locales An array of ordered available locales
*
* @return string The preferred locale
* @return string|null The preferred locale
*
* @api
*/
......@@ -911,7 +935,7 @@ public function getPreferredLanguage(array $locales = null)
{
$preferredLanguages = $this->getLanguages();
if (null === $locales) {
if (empty($locales)) {
return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
}
......@@ -1017,6 +1041,8 @@ public function isXmlHttpRequest()
* Splits an Accept-* HTTP header.
*
* @param string $header Header to split
*
* @return array Array indexed by the values of the Accept-* header in preferred order
*/
public function splitHttpAcceptHeader($header)
{
......@@ -1027,9 +1053,9 @@ public function splitHttpAcceptHeader($header)
$values = array();
foreach (array_filter(explode(',', $header)) as $value) {
// Cut off any q-value that might come after a semi-colon
if ($pos = strpos($value, ';')) {
$q = (float) trim(substr($value, strpos($value, '=') + 1));
$value = trim(substr($value, 0, $pos));
if (preg_match('/;\s*(q=.*$)/', $value, $match)) {
$q = (float) substr(trim($match[1]), 2);
$value = trim(substr($value, 0, -strlen($match[0])));
} else {
$q = 1;
}
......@@ -1057,7 +1083,7 @@ protected function prepareRequestUri()
{
$requestUri = '';
if ($this->headers->has('X_REWRITE_URL')) {
if ($this->headers->has('X_REWRITE_URL') && false !== stripos(PHP_OS, 'WIN')) {
// check this first so IIS will catch
$requestUri = $this->headers->get('X_REWRITE_URL');
} elseif ($this->server->get('IIS_WasUrlRewritten') == '1' && $this->server->get('UNENCODED_URL') != '') {
......
......@@ -135,7 +135,7 @@ protected function checkIp($requestIp, $ip)
protected function checkIp4($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
list($address, $netmask) = explode('/', $ip);
list($address, $netmask) = explode('/', $ip, 2);
if ($netmask < 1 || $netmask > 32) {
return false;
......@@ -158,14 +158,14 @@ protected function checkIp6($requestIp, $ip)
throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".');
}
list($address, $netmask) = explode('/', $ip);
list($address, $netmask) = explode('/', $ip, 2);
$bytes_addr = unpack("n*", inet_pton($address));
$bytes_test = unpack("n*", inet_pton($requestIp));
for ($i = 1, $ceil = ceil($netmask / 16); $i <= $ceil; $i++) {
$left = $netmask - 16 * ($i-1);
$left = ($left <= 16) ?: 16;
$left = ($left <= 16) ? $left : 16;
$mask = ~(0xffff >> $left) & 0xffff;
if (($bytes_addr[$i] & $mask) != ($bytes_test[$i] & $mask)) {
return false;
......
......@@ -134,7 +134,7 @@ public function prepare()
$charset = $this->charset ?: 'UTF-8';
if (!$this->headers->has('Content-Type')) {
$this->headers->set('Content-Type', 'text/html; charset='.$charset);
} elseif ('text/' === substr($this->headers->get('Content-Type'), 0, 5) && false === strpos($this->headers->get('Content-Type'), 'charset')) {
} elseif (0 === strpos($this->headers->get('Content-Type'), 'text/') && false === strpos($this->headers->get('Content-Type'), 'charset')) {
// add the charset
$this->headers->set('Content-Type', $this->headers->get('Content-Type').'; charset='.$charset);
}
......@@ -197,7 +197,7 @@ public function send()
}
/**
* Sets the response content
* Sets the response content.
*
* Valid types are strings, numbers, and objects that implement a __toString() method.
*
......@@ -215,7 +215,7 @@ public function setContent($content)
}
/**
* Gets the current response content
* Gets the current response content.
*
* @return string Content
*
......@@ -251,7 +251,7 @@ public function getProtocolVersion()
}
/**
* Sets response status code.
* Sets the response status code.
*
* @param integer $code HTTP status code
* @param string $text HTTP status text
......@@ -271,7 +271,7 @@ public function setStatusCode($code, $text = null)
}
/**
* Retrieves status code for the current web response.
* Retrieves the status code for the current web response.
*
* @return string Status code
*
......@@ -283,7 +283,7 @@ public function getStatusCode()
}
/**
* Sets response charset.
* Sets the response charset.
*
* @param string $charset Character set
*
......@@ -409,7 +409,7 @@ public function mustRevalidate()
*
* @return \DateTime A \DateTime instance
*
* @throws \RuntimeException when the header is not parseable
* @throws \RuntimeException When the header is not parseable
*
* @api
*/
......@@ -470,7 +470,7 @@ public function getExpires()
}
/**
* Sets the Expires HTTP header with a \DateTime instance.
* Sets the Expires HTTP header with a DateTime instance.
*
* If passed a null value, it removes the header.
*
......@@ -522,7 +522,7 @@ public function getMaxAge()
*
* This methods sets the Cache-Control max-age directive.
*
* @param integer $value A number of seconds
* @param integer $value Number of seconds
*
* @api
*/
......@@ -536,7 +536,7 @@ public function setMaxAge($value)
*
* This methods sets the Cache-Control s-maxage directive.
*
* @param integer $value A number of seconds
* @param integer $value Number of seconds
*
* @api
*/
......@@ -572,7 +572,7 @@ public function getTtl()
*
* This method adjusts the Cache-Control/s-maxage directive.
*
* @param integer $seconds The number of seconds
* @param integer $seconds Number of seconds
*
* @api
*/
......@@ -586,7 +586,7 @@ public function setTtl($seconds)
*
* This method adjusts the Cache-Control/max-age directive.
*
* @param integer $seconds The number of seconds
* @param integer $seconds Number of seconds
*
* @api
*/
......@@ -608,7 +608,7 @@ public function getLastModified()
}
/**
* Sets the Last-Modified HTTP header with a \DateTime instance.
* Sets the Last-Modified HTTP header with a DateTime instance.
*
* If passed a null value, it removes the header.
*
......@@ -628,7 +628,7 @@ public function setLastModified(\DateTime $date = null)
}
/**
* Returns the literal value of ETag HTTP header.
* Returns the literal value of the ETag HTTP header.
*
* @return string The ETag HTTP header
*
......@@ -661,7 +661,7 @@ public function setEtag($etag = null, $weak = false)
}
/**
* Sets Response cache headers (validation and/or expiration).
* Sets the response's cache headers (validation and/or expiration).
*
* Available options are: etag, last_modified, max_age, s_maxage, private, and public.
*
......@@ -672,7 +672,7 @@ public function setEtag($etag = null, $weak = false)
public function setCache(array $options)
{
if ($diff = array_diff(array_keys($options), array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public'))) {
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_keys($diff))));
throw new \InvalidArgumentException(sprintf('Response does not support the following options: "%s".', implode('", "', array_values($diff))));
}
if (isset($options['etag'])) {
......@@ -771,15 +771,15 @@ public function setVary($headers, $replace = true)
}
/**
* Determines if the Response validators (ETag, Last-Modified) matches
* Determines if the Response validators (ETag, Last-Modified) match
* a conditional value specified in the Request.
*
* If the Response is not modified, it sets the status code to 304 and
* remove the actual content by calling the setNotModified() method.
* removes the actual content by calling the setNotModified() method.
*
* @param Request $request A Request instance
*
* @return Boolean true if the Response validators matches the Request, false otherwise
* @return Boolean true if the Response validators match the Request, false otherwise
*
* @api
*/
......
......@@ -120,6 +120,7 @@ public function getCacheControlDirective($key)
* Sets a cookie.
*
* @param Cookie $cookie
*
* @return void
*
* @api
......@@ -135,6 +136,7 @@ public function setCookie(Cookie $cookie)
* @param string $name
* @param string $path
* @param string $domain
*
* @return void
*
* @api
......@@ -195,6 +197,7 @@ public function getCookies($format = self::COOKIES_FLAT)
* @param string $name
* @param string $path
* @param string $domain
*
* @return void
*
* @api
......
......@@ -23,7 +23,7 @@ public function getHeaders()
{
$headers = array();
foreach ($this->parameters as $key => $value) {
if ('HTTP_' === substr($key, 0, 5)) {
if (0 === strpos($key, 'HTTP_')) {
$headers[substr($key, 5)] = $value;
}
// CONTENT_* are not prefixed with HTTP_
......
......@@ -94,7 +94,8 @@ public function getId()
*
* The preferred format for a key is directory style so naming conflicts can be avoided.
*
* @param string $key A unique key identifying your data
* @param string $key A unique key identifying your data
* @param string $default The default value
*
* @return mixed Data associated with the key
*
......
......@@ -143,7 +143,6 @@ public function sessionGC($lifetime)
$sql = "DELETE FROM $dbTable WHERE $dbTimeCol < (:time - $lifetime)";
try {
$this->db->query($sql);
$stmt = $this->db->prepare($sql);
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
$stmt->execute();
......@@ -182,7 +181,7 @@ public function sessionRead($id)
$sessionRows = $stmt->fetchAll(\PDO::FETCH_NUM);
if (count($sessionRows) == 1) {
return $sessionRows[0][0];
return base64_decode($sessionRows[0][0]);
}
// session does not exist, create it
......@@ -218,9 +217,11 @@ public function sessionWrite($id, $data)
: "UPDATE $dbTable SET $dbDataCol = :data, $dbTimeCol = :time WHERE $dbIdCol = :id";
try {
//session data can contain non binary safe characters so we need to encode it
$encoded = base64_encode($data);
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
$stmt->bindParam(':data', $data, \PDO::PARAM_STR);
$stmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
$stmt->execute();
......@@ -252,9 +253,11 @@ private function createNewSession($id, $data = '')
$sql = "INSERT INTO $dbTable ($dbIdCol, $dbDataCol, $dbTimeCol) VALUES (:id, :data, :time)";
//session data can contain non binary safe characters so we need to encode it
$encoded = base64_encode($data);
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':id', $id, \PDO::PARAM_STR);
$stmt->bindParam(':data', $data, \PDO::PARAM_STR);
$stmt->bindParam(':data', $encoded, \PDO::PARAM_STR);
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
$stmt->execute();
......
......@@ -4,7 +4,6 @@
"description": "Symfony HttpFoundation Component",
"keywords": [],
"homepage": "http://symfony.com",
"version": "2.0.4",
"license": "MIT",
"authors": [
{
......@@ -18,5 +17,9 @@
],
"require": {
"php": ">=5.3.2"
}
},
"autoload": {
"psr-0": { "Symfony\\Component\\HttpFoundation": "" }
},
"target-dir": "Symfony/Component/HttpFoundation"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment