8000 Merge branch '2.0' into 2.1 · symfony/symfony@e425f6c · GitHub
[go: up one dir, main page]

Skip to content

Commit e425f6c

Browse files
committed
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
2 parents 03f1ccc + 9122260 commit e425f6c

File tree

8 files changed

+40
-7
lines changed

8 files changed

+40
-7
lines changed

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function validate($entity, Constraint $constraint)
7070
$criteria = array();
7171
foreach ($fields as $fieldName) {
7272
if (!$class->hasField($fieldName) && !$class->hasAssociation($fieldName)) {
73-
throw new ConstraintDefinitionException("Only field names mapped by Doctrine can be validated for uniqueness.");
73+
throw new ConstraintDefinitionException(sprintf("The field '%s' is not mapped by Doctrine, so it cannot be validated for uniqueness.", $fieldName));
7474
}
7575

7676
$criteria[$fieldName] = $class->reflFields[$fieldName]->getValue($entity);

src/Symfony/Component/Console/Input/InputArgument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function isArray()
9696
public function setDefault($default = null)
9797
{
9898
if (self::REQUIRED === $this->mode && null !== $default) {
99-
throw new \LogicException('Cannot set a default value except for Parameter::OPTIONAL mode.');
99+
throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
100100
}
101101

102102
if ($this->isArray()) {

src/Symfony/Component/Console/Input/InputOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function isArray()
156156
public function setDefault($default = null)
157157
{
158158
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
159-
throw new \LogicException('Cannot set a default value when using Option::VALUE_NONE mode.');
159+
throw new \LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
160160
}
161161

162162
if ($this->isArray()) {

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ public function reverseTransform($value)
108108
}
109109

110110
$formatter = $this->getNumberFormatter();
111+
$groupSep = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
112+
$decSep = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
113+
114+
if ('.' !== $decSep && (!$this->grouping || '.' !== $groupSep)) {
115+
$value = str_replace('.', $decSep, $value);
116+
}
117+
118+
if (',' !== $decSep && (!$this->grouping || ',' !== $groupSep)) {
119+
$value = str_replace(',', $decSep, $value);
120+
}
121+
111122
$value = $formatter->parse($value);
112123

113124
if (intl_is_failure($formatter->getErrorCode())) {

src/Symfony/Component/HttpFoundation/File/File.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function move($directory, $name = null)
115115
throw new FileException(sprintf('Unable to write in the "%s" directory', $directory));
116116
}
117117

118-
$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : basename($name));
118+
$target = $directory.DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));
119119

120120
if (!@rename($this->getPathname(), $target)) {
121121
$error = error_get_last();
@@ -126,4 +126,20 @@ public function move($directory, $name = null)
126126

127127
return new File($target);
128128
}
129+
130+
/**
131+
* Returns locale independent base name of the given path.
132+
*
133+
* @param string $name The new file name
134+
*
135+
* @return string containing
136+
*/
137+
protected function getName($name)
138+
{
139+
$originalName = str_replace('\\', '/', $name);
140+
$pos = strrpos($originalName, '/');
141+
$originalName = false === $pos ? $originalName : substr($originalName, $pos + 1);
142+
143+
return $originalName;
144+
}
129145
}

src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function __construct($path, $originalName, $mimeType = null, $size = null
9494
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')));
9595
}
9696

97-
$this->originalName = basename($originalName);
97+
$this->originalName = $this->getName($originalName);
9898
$this->mimeType = $mimeType ?: 'application/octet-stream';
9999
$this->size = $size;
100100
$this->error = $error ?: UPLOAD_ERR_OK;
@@ -166,7 +166,7 @@ public function getError()
166166
/**
167167
* Returns whether the file was uploaded successfully.
168168
*
169-
* @return Boolean True if no error occurred during uploading
169+
* @return Boolean True if no error occurred during uploading
170170
*
171171
* @api
172172
*/

src/Symfony/Component/HttpKernel/HttpCache/Store.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ public function lock(Request $request)
8686
* Releases the lock for the given Request.
8787
*
8888
* @param Request $request A Request instance
89+
*
90+
* @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise
8991
*/
9092
public function unlock(Request $request)
9193
{
92-
return @unlink($this->getPath($this->getCacheKey($request).'.lck'));
94+
$file = $this->getPath($this->getCacheKey($request).'.lck');
95+
96+
return is_file($file) ? @unlink($file) : false;
9397
}
9498

9599
/**

src/Symfony/Component/HttpKernel/HttpCache/StoreInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function lock(Request $request);
6666
* Releases the lock for the given Request.
6767
*
6868
* @param Request $request A Request instance
69+
*
70+
* @return Boolean False if the lock file does not exist or cannot be unlocked, true otherwise
6971
*/
7072
public function unlock(Request $request);
7173

0 commit comments

Comments
 (0)
0