8000 Merge branch '2.3' into 2.7 · symfony/symfony@da655a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit da655a9

Browse files
committed
Merge branch '2.3' into 2.7
* 2.3: Typo fix [2.3] Static Code Analysis for Components Added support \IteratorAggregate for UniqueEntityValidator Fix #17306 Paths with % in it are note allowed (like urlencoded) Added sort order SORT_STRING for params in UriSigner Remove normalizer cache in Serializer class
2 parents ab00f68 + 406e260 commit da655a9

File tree

23 files changed

+131
-53
lines changed

23 files changed

+131
-53
lines changed

UPGRADE-3.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ UPGRADE FROM 2.x to 3.0
1010
| -------- | ---
1111
| `registerNamespaces()` | `addPrefixes()`
1212
| `registerPrefixes()` | `addPrefixes()`
13-
| `registerNamespaces()` | `addPrefix()`
14-
| `registerPrefixes()` | `addPrefix()`
13+
| `registerNamespace()` | `addPrefix()`
14+
| `registerPrefix()` | `addPrefix()`
1515
| `getNamespaces()` | `getPrefixes()`
1616
| `getNamespaceFallbacks()` | `getFallbackDirs()`
1717
| `getPrefixFallbacks()` | `getFallbackDirs()`

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Doctrine\Tests\Validator\Constraints;
1313

14+
use Doctrine\Common\Collections\ArrayCollection;
1415
use Doctrine\Common\Persistence\ManagerRegistry;
1516
use Doctrine\Common\Persistence\ObjectManager;
1617
use Doctrine\Common\Persistence\ObjectRepository;
@@ -336,6 +337,44 @@ public function testValidateUniquenessWithUnrewoundArray()
336337
$this->assertNoViolation();
337338
}
338339

340+
/**
341+
* @dataProvider resultTypesProvider
342+
*/
343+
public function testValidateResultTypes($entity1, $result)
344+
{
345+
$constraint = new UniqueEntity(array(
346+
'message' => 'myMessage',
347+
'fields' => array('name'),
348+
'em' => self::EM_NAME,
349+
'repositoryMethod' => 'findByCustom',
350+
));
351+
352+
$repository = $this->createRepositoryMock();
353+
$repository->expects($this->once())
354+
->method('findByCustom')
355+
->will($this->returnValue($result))
356+
;
357+
$this->em = $this->createEntityManagerMock($repository);
358+
$this->registry = $this->createRegistryMock($this->em);
359+
$this->validator = $this->createValidator();
360+
$this->validator->initialize($this->context);
361+
362+
$this->validator->validate($entity1, $constraint);
363+
364+
$this->assertNoViolation();
365+
}
366+
367+
public function resultTypesProvider()
368+
{
369+
$entity = new SingleIntIdEntity(1, 'foo');
370+
371+
return array(
372+
array($entity, array($entity)),
373+
array($entity, new \ArrayIterator(array($entity))),
374+
array($entity, new ArrayCollection(array($entity))),
375+
);
376+
}
377+
339378
public function testAssociatedEntity()
340379
{
341380
$constraint = new UniqueEntity(array(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ public function validate($entity, Constraint $constraint)
114114
$repository = $em->getRepository(get_class($entity));
115115
$result = $repository->{$constraint->repositoryMethod}($criteria);
116116

117+
if ($result instanceof \IteratorAggregate) {
118+
$result = $result->getIterator();
119+
}
120+
117121
/* If the result is a MongoCursor, it must be advanced to the first
118122
* element. Rewinding should have no ill effect if $result is another
119123
* iterator implementation.

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,17 +685,17 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
685685

686686
$dirs[] = dirname($r->getFileName()).'/../Resources/translations';
687687
}
688-
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
688+
$rootDir = $container->getParameter('kernel.root_dir');
689689
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
690690
$reflection = new \ReflectionClass($class);
691691
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
692692
$dirs[] = $dir;
693693
}
694-
if (is_dir($dir = sprintf($overridePath, $bundle))) {
694+
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
695695
$dirs[] = $dir;
696696
}
697697
}
698-
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
698+
if (is_dir($dir = $rootDir.'/Resources/translations')) {
699699
$dirs[] = $dir;
700700
}
701701

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function setServerParameter($key, $value)
129129
*/
130130
public function getServerParameter($key, $default = '')
131131
{
132-
return (isset($this->server[$key])) ? $this->server[$key] : $default;
132+
return isset($this->server[$key]) ? $this->server[$key] : $default;
133133
}
134134

135135
/**

src/Symfony/Component/Console/Helper/TableHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function setLayout($layout)
6969

7070
default:
7171
throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
72-
};
72+
}
7373

7474
return $this;
7575
}

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function_exists('php_uname') ? php_uname('s') : '',
131131
PHP_OS,
132132
);
133133

134-
return false !== stristr(implode(';', $checks), 'OS400');
134+
return false !== stripos(implode(';', $checks), 'OS400');
135135
}
136136

137137
/**

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,6 @@ public static function camelize($id)
534534
*/
535535
public static function underscore($id)
536536
{
537-
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
537+
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id)));
538538
}
539539
}

src/Symfony/Component/DependencyInjection/Extension/Extension.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ public function getConfiguration(array $config, ContainerBuilder $container)
9191
$container->addResource(new FileResource($r->getFileName()));
9292

9393
if (!method_exists($class, '__construct')) {
94-
$configuration = new $class();
95-
96-
return $configuration;
94+
return new $class();
9795
}
9896
}
9997
}

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ private function parseImports(\DOMDocument $xml, $file)
9393
return;
9494
}
9595

96+
$defaultDirectory = dirname($file);
9697
foreach ($imports as $import) {
97-
57AE $this->setCurrentDir(dirname($file));
98+
$this->setCurrentDir($defaultDirectory);
9899
$this->import($import->getAttribute('resource'), null, (bool) XmlUtils::phpize($import->getAttribute('ignore-errors')), $file);
99100
}
100101
}

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ private function parseImports($content, $file)
9595
throw new InvalidArgumentException(sprintf('The "imports" key should contain an array in %s. Check your YAML syntax.', $file));
9696
}
9797

98+
$defaultDirectory = dirname($file);
9899
foreach ($content['imports'] as $import) {
99100
if (!is_array($import)) {
100101
throw new InvalidArgumentException(sprintf('The values in the "imports" key should be arrays in %s. Check your YAML syntax.', $file));
101102
}
102103

103-
$this->setCurrentDir(dirname($file));
104+
$this->setCurrentDir($defaultDirectory);
104105
$this->import($import['resource'], null, isset($import['ignore_errors']) ? (bool) $import['ignore_errors'] : false, $file);
105106
}
106107
}

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public function isAbsolutePath($file)
446446
return strspn($file, '/\\', 0, 1)
447447
|| (strlen($file) > 3 && ctype_alpha($file[0])
448448
&& substr($file, 1, 1) === ':'
449-
&& (strspn($file, '/\\', 2, 1))
449+
&& strspn($file, '/\\', 2, 1)
450450
)
451451
|| null !== parse_url($file, PHP_URL_SCHEME)
452452
;

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function add(array $headers)
111111
*/
112112
public function get($key, $default = null, $first = true)
113113
{
114-
$key = strtr(strtolower($key), '_', '-');
114+
$key = str_replace('_', '-', strtolower($key));
115115

116116
if (!array_key_exists($key, $this->headers)) {
117117
if (null === $default) {
@@ -137,7 +137,7 @@ public function get($key, $default = null, $first = true)
137137
*/
138138
public function set($key, $values, $replace = true)
139139
{
140-
$key = strtr(strtolower($key), '_', '-');
140+
$key = str_replace('_', '-', strtolower($key));
141141

142142
$values = array_values((array) $values);
143143

@@ -161,7 +161,7 @@ public function set($key, $values, $replace = true)
161161
*/
162162
public function has($key)
163163
{
164-
return array_key_exists(strtr(strtolower($key), '_', '-'), $this->headers);
164+
return array_key_exists(str_replace('_', '-', strtolower($key)), $this->headers);
165165
}
166166

167167
/**
@@ -184,7 +184,7 @@ public function contains($key, $value)
184184
*/
185185
public function remove($key)
186186
{
187-
$key = strtr(strtolower($key), '_', '-');
187+
$key = str_replace('_', '-', strtolower($key));
188188

189189
unset($this->headers[$key]);
190190

src/Symfony/Component/HttpFoundation/ResponseHeaderBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function set($key, $values, $replace = true)
9999
{
100100
parent::set($key, $values, $replace);
101101

102-
$uniqueKey = strtr(strtolower($key), '_', '-');
102+
$uniqueKey = str_replace('_', '-', strtolower($key));
103103
$this->headerNames[$uniqueKey] = $key;
104104

105105
// ensure the cache-control header has sensible defaults
@@ -118,7 +118,7 @@ public function remove($key)
118118
{
119119
parent::remove($key);
120120

121-
$uniqueKey = strtr(strtolower($key), '_', '-');
121+
$uniqueKey = str_replace('_', '-', strtolower($key));
122122
unset($this->headerNames[$uniqueKey]);
123123

124124
if ('cache-control' === $uniqueKey) {

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function registerCommands(Application $application)
177177
foreach ($finder as $file) {
178178
$ns = $prefix;
179179
if ($relativePath = $file->getRelativePath()) {
180-
$ns .= '\\'.strtr($relativePath, '/', '\\');
180+
$ns .= '\\'.str_replace('/', '\\', $relativePath);
181181
}
182182
$class = $ns.'\\'.$file->getBasename('.php');
183183
if ($this->container) {

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ class Store implements StoreInterface
3838
public function __construct($root)
3939
{
4040
$this->root = $root;
41-
if (!is_dir($this->root)) {
42-
if (false === @mkdir($this->root, 0777, true) && !is_dir($this->root)) {
43-
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
44-
}
41+
if (!is_dir($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) {
42+
throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root));
4543
}
4644
$this->keyCache = new \SplObjectStorage();
4745
$this->locks = array();
@@ -249,10 +247,8 @@ public function invalidate(Request $request)
249247
}
250248
}
251249

252-
if ($modified) {
253-
if (false === $this->save($key, serialize($entries))) {
254-
throw new \RuntimeException('Unable to store the metadata.');
255-
}
250+
if ($modified && false === $this->save($key, serialize($entries))) {
251+
throw new \RuntimeException('Unable to store the metadata.');
256252
}
257253
}
258254

@@ -273,7 +269,7 @@ private function requestsMatch($vary, $env1, $env2)
273269
}
274270

275271
foreach (preg_split('/[\s,]+/', $vary) as $header) {
276-
$key = strtr(strtolower($header), '_', '-');
272+
$key = str_replace('_', '-', strtolower($header));
277273
$v1 = isset($env1[$key]) ? $env1[$key] : null;
278274
$v2 = isset($env2[$key]) ? $env2[$key] : null;
279275
if ($v1 !== $v2) {

src/Symfony/Component/HttpKernel/Profiler/PdoProfilerStorage.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,8 @@ protected function fetch($db, $query, array $args = array())
188188
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
189189
}
190190
$stmt->execute();
191-
$return = $stmt->fetchAll(\PDO::FETCH_ASSOC);
192191

193-
return $return;
192+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
194193
}
195194

196195
protected function close($db)

src/Symfony/Component/HttpKernel/Tests/UriSignerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function testCheck()
3333

3434
$this->assertTrue($signer->check($signer->sign('http://example.com/foo')));
3535
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar')));
36+
$this->assertTrue($signer->check($signer->sign('http://example.com/foo?foo=bar&0=integer')));
3637

3738
$this->assertTrue($signer->sign('http://example.com/foo?foo=bar&bar=foo') === $signer->sign('http://example.com/foo?bar=foo&foo=bar'));
3839
}

src/Symfony/Component/HttpKernel/UriSigner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function sign($uri)
5151

5252
$uri = $this->buildUrl($url, $params);
5353

54-
return $uri.(false === (strpos($uri, '?')) ? '?' : '&').'_hash='.$this->computeHash($uri);
54+
return $uri.(false === strpos($uri, '?') ? '?' : '&').'_hash='.$this->computeHash($uri);
5555
}
5656

5757
/**
@@ -91,7 +91,7 @@ private function computeHash($uri)
9191

9292
private function buildUrl(array $url, array $params = array())
9393
{
94-
ksort($params);
94+
ksort($params, SORT_STRING);
9595
$url['query'] = http_build_query($params, '', '&');
9696

9797
$scheme = isset($url['scheme']) ? $url['scheme'].'://' : '';

src/Symfony/Component/Security/Http/Firewall/DigestAuthenticationListener.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,8 @@ public function validateAndDecode($entryPointKey, $expectedRealm)
171171
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s" (%s)', $this->header, implode(', ', $keys)));
172172
}
173173

174-
if ('auth' === $this->elements['qop']) {
175-
if (!isset($this->elements['nc']) || !isset($this->elements['cnonce'])) {
176-
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header));
177-
}
174+
if ('auth' === $this->elements['qop'] && !isset($this->elements['nc'], $this->elements['cnonce'])) {
175+
throw new BadCredentialsException(sprintf('Missing mandatory digest value; received header "%s"', $this->header));
178176
}
179177

180178
if ($expectedRealm !== $this->elements['realm']) {

src/Symfony/Component/Serializer/Serializer.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,10 @@ private function getNormalizer($data, $format)
187187
{
188188
if ($isObject = is_object($data)) {
189189
$class = get_class($data);
190-
if (isset($this->normalizerCache[$class][$format])) {
191-
return $this->normalizerCache[$class][$format];
192-
}
193190
}
194191

195192
foreach ($this->normalizers as $normalizer) {
196193
if ($normalizer instanceof NormalizerInterface && $normalizer->supportsNormalization($data, $format)) {
197-
if ($isObject) {
198-
$this->normalizerCache[$class][$format] = $normalizer;
199-
}
200-
201194
return $normalizer;
202195
}
203196
}
@@ -214,14 +207,8 @@ private function getNormalizer($data, $format)
214207
*/
215208
private function getDenormalizer($data, $class, $format)
216209
{
217-
if (isset($this->denormalizerCache[$class][$format])) {
218-
return $this->denormalizerCache[$class][$format];
219-
}
220-
221210
foreach ($this->normalizers as $normalizer) {
222211
if ($normalizer instanceof DenormalizerInterface && $normalizer->supportsDenormalization($data, $class, $format)) {
223-
$this->denormalizerCache[$class][$format] = $normalizer;
224-
225212
return $normalizer;
226213
}
227214
}
@@ -264,6 +251,7 @@ private function normalizeObject($object, $format, array $context = array())
264251
if ($normalizer = $this->getNormalizer($object, $format)) {
265252
return $normalizer->normalize($object, $format, $context);
266253
}
254+
267255
throw new UnexpectedValueException(sprintf('Could not normalize object of type %s, no supporting normalizer found.', get_class($object)));
268256
}
269257

@@ -289,6 +277,15 @@ private function denormalizeObject($data, $class, $format, array $context = arra
289277
if ($normalizer = $this->getDenormalizer($data, $class, $format)) {
290278
return $normalizer->denormalize($data, $class, $format, $context);
291279
}
280+
281+
foreach ($this->normalizers as $normalizer) {
282+
if ($normalizer instanceof DenormalizerInterface
283+
&& $normalizer->supportsDenormalization($data, $class, $format)) {
284+
285+
return $normalizer->denormalize($data, $class, $format, $context);
286+
}
287+
}
288+
292289
throw new UnexpectedValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $class));
293290
}
294291

0 commit comments

Comments
 (0)
0