Merge branch '2.0' into 2.1

* 2.0:
  [Form] Fixed NumberToLocalizedStringTransformer to accept both comma and dot as decimal separator, if possible
  Show correct class name InputArgument in error message
  shows correct class name InputOption in error message
  The exception message should say which field is not mapped
  [HttpFoundation] Fix name sanitization after perfoming move
  Add check to Store::unlock to ensure file exists

Conflicts:
	src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
	src/Symfony/Component/HttpFoundation/File/UploadedFile.php
	tests/Symfony/Tests/Component/Console/Input/InputArgumentTest.php
	tests/Symfony/Tests/Component/Console/Input/InputOptionTest.php
	tests/Symfony/Tests/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php
	tests/Symfony/Tests/Component/HttpFoundation/File/FileTest.php
	tests/Symfony/Tests/Component/HttpKernel/HttpCache/StoreTest.php
This commit is contained in:
Fabien Potencier 2012-11-08 18:02:05 +01:00
commit e425f6cf9a
8 changed files with 40 additions and 7 deletions

View File

@ -70,7 +70,7 @@ class UniqueEntityValidator extends ConstraintValidator
$criteria = array();
foreach ($fields as $fieldName) {
if (!$class->hasField($fieldName) && !$class->hasAssociation($fieldName)) {
throw new ConstraintDefinitionException("Only field names mapped by Doctrine can be validated for uniqueness.");
throw new ConstraintDefinitionException(sprintf("The field '%s' is not mapped by Doctrine, so it cannot be validated for uniqueness.", $fieldName));
}
$criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity);

View File

@ -96,7 +96,7 @@ class InputArgument
public function setDefault($default = null)
{
if (self::REQUIRED === $this->mode && null !== $default) {
throw new \LogicException('Cannot set a default value except for Parameter::OPTIONAL mode.');
throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
}
if ($this->isArray()) {

View File

@ -156,7 +156,7 @@ class InputOption
public function setDefault($default = null)
{
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
throw new \LogicException('Cannot set a default value when using Option::VALUE_NONE mode.');
throw new \LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
}
if ($this->isArray()) {

View File

@ -108,6 +108,17 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
}
$formatter = $this->getNumberFormatter();
$groupSep = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
$decSep = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
if ('.' !== $decSep && (!$this->grouping || '.' !== $groupSep)) {
$value = str_replace('.', $decSep, $value);
}
if (',' !== $decSep && (!$this->grouping || ',' !== $groupSep)) {
$value = str_replace(',', $decSep, $value);
}
$value = $formatter->parse($value);
if (intl_is_failure($formatter->getErrorCode())) {

View File

@ -115,7 +115,7 @@ class File extends \SplFileInfo
throw new FileException(sprintf('Unable to write in the "%s" directory', $directory));
}
$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : basename($name));
$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));
if (!@rename($this->getPathname(), $target)) {
$error = error_get_last();
@ -126,4 +126,20 @@ class File extends \SplFileInfo
return new File($target);
}
/**
* Returns locale independent base name of the given path.
*
* @param string $name The new file name
*
* @return string containing
*/
protected function getName($name)
{
$originalName = str_replace('\\', '/', $name);
$pos = strrpos($originalName, '/');
$originalName = false === $pos ? $originalName : substr($originalName, $pos + 1);
return $originalName;
}
}

View File

@ -94,7 +94,7 @@ class UploadedFile extends File
throw new FileException(sprintf('Unable to create UploadedFile because "file_uploads" is disabled in your php.ini file (%s)', get_cfg_var('cfg_file_path')));
}
$this->originalName = basename($originalName);
$this->originalName = $this->getName($originalName);
$this->mimeType = $mimeType ?: 'application/octet-stream';
$this->size = $size;
$this->error = $error ?: UPLOAD_ERR_OK;
@ -166,7 +166,7 @@ class UploadedFile extends File
/**
* Returns whether the file was uploaded successfully.
*
* @return Boolean True if no error occurred during uploading
* @return Boolean True if no error occurred during uploading
*
* @api
*/

View File

@ -86,10 +86,14 @@ class Store implements StoreInterface
* Releases the lock for the given Request.
*
* @param Request $request A Request instance
*
* @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise
*/
public function unlock(Request $request)
{
return @unlink($this->getPath($this->getCacheKey($request).'.lck'));
$file = $this->getPath($this->getCacheKey($request).'.lck');
return is_file($file) ? @unlink($file) : false;
}
/**

View File

@ -66,6 +66,8 @@ interface StoreInterface
* Releases the lock for the given Request.
*
* @param Request $request A Request instance
*
* @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise
*/
public function unlock(Request $request);