Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ed54a3

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Typo fix [2.3] Static Code Analysis for Components Added support \IteratorAggregate for UniqueEntityValidator Update AbstractChoiceListTest.php Fix #17306 Paths with % in it are note allowed (like urlencoded) Use proper class to fetch $versionStrategy property Added sort order SORT_STRING for params in UriSigner Remove normalizer cache in Serializer class
2 parents 3331c8a + da655a9 commit 4ed54a3

File tree

27 files changed

+145
-63
lines changed

27 files changed

+145
-63
lines changed

UPGRADE-3.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ UPGRADE FROM 2.x to 3.0
1010
| -------- | ---
1111
| `registerNamespaces()` | `addPrefixes()`
1212
| `registerPrefixes()` | `addPrefixes()`
13-
| `registerNamespaces()` | `addPrefix()`
13+
| `registerNamespace()` | `addPrefix()`
1414
| `registerPrefix()` | `addPrefix()`
1515
| `getNamespaces()` | `getPrefixes()`
1616
| `getNamespaceFallbacks()` | `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/Bridge/Twig/Extension/AssetExtension.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,16 @@ private function getLegacyAssetUrl($path, $packageName = null, $absolute = false
9898
{
9999
if ($version) {
100100
$package = $this->packages->getPackage($packageName);
101-
$class = new \ReflectionClass($package);
102101

103-
while ('Symfony\Component\Asset\Package' !== $class->getName()) {
104-
$class = $class->getParentClass();
105-
}
106-
107-
$v = $class->getProperty('versionStrategy');
102+
$v = new \ReflectionProperty('Symfony\Component\Asset\Package', 'versionStrategy');
108103
$v->setAccessible(true);
104+
109105
$currentVersionStrategy = $v->getValue($package);
110106

111107
if (property_exists($currentVersionStrategy, 'format')) {
112108
$f = new \ReflectionProperty($currentVersionStrategy, 'format');
113109
$f->setAccessible(true);
110+
114111
$format = $f->getValue($currentVersionStrategy);
115112

116113
$v->setValue($package, new StaticVersionStrategy($version, $format));

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,24 +689,26 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
689689

690690
$dirs[] = dirname($r->getFileName()).'/../Resources/translations';
691691
}
692-
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
692+
$rootDir = $container->getParameter('kernel.root_dir');
693693
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
694694
$reflection = new \ReflectionClass($class);
695695
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
696696
$dirs[] = $dir;
697697
}
698-
if (is_dir($dir = sprintf($overridePath, $bundle))) {
698+
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
699699
$dirs[] = $dir;
700700
}
701701
}
702+
702703
foreach ($config['paths'] as $dir) {
703704
if (is_dir($dir)) {
704705
$dirs[] = $dir;
705706
} else {
706707
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
707708
}
708709
}
709-
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
710+
711+
if (is_dir($dir = $rootDir.'/Resources/translations')) {
710712
$dirs[] = $dir;
711713
}
712714

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/AssetsHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ private function getLegacyAssetUrl($path, $packageName = null, $version = null)
9595
if ($version) {
9696
$package = $this->packages->getPackage($packageName);
9797

98-
$v = new \ReflectionProperty($package, 'versionStrategy');
98+
$v = new \ReflectionProperty('Symfony\Component\Asset\Package', 'versionStrategy');
9999
$v->setAccessible(true);
100100

101101
$currentVersionStrategy = $v->getValue($package);
102102

103103
$f = new \ReflectionProperty($currentVersionStrategy, 'format');
104104
$f->setAccessible(true);
105+
105106
$format = $f->getValue($currentVersionStrategy);
106107

107108
$v->setValue($package, new StaticVersionStrategy($version, $format));

src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/AssetsHelperTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\FrameworkBundle\Templating\Helper\AssetsHelper;
1515
use Symfony\Component\Asset\Package;
1616
use Symfony\Component\Asset\Packages;
17+
use Symfony\Component\Asset\PathPackage;
1718
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
1819

1920
class AssetsHelperTest extends \PHPUnit_Framework_TestCase
@@ -23,11 +24,14 @@ class AssetsHelperTest extends \PHPUnit_Framework_TestCase
2324
*/
2425
public function testLegacyGetUrl()
2526
{
26-
$package = new Package(new StaticVersionStrategy('22', '%s?version=%s'));
27-
$packages = new Packages($package);
27+
$versionStrategy = new StaticVersionStrategy('22', '%s?version=%s');
28+
$package = new Package($versionStrategy);
29+
$imagePackage = new PathPackage('images', $versionStrategy);
30+
$packages = new Packages($package, array('images' => $imagePackage));
2831
$helper = new AssetsHelper($packages);
2932

3033
$this->assertEquals('me.png?version=42', $helper->getUrl('me.png', null, '42'));
34+
$this->assertEquals('/images/me.png?version=42', $helper->getUrl('me.png', 'images', '42'));
3135
}
3236

3337
/**

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function setServerParameter($key, $value)
149149
*/
150150
public function getServerParameter($key, $default = '')
151151
{
152-
return (isset($this->server[$key])) ? $this->server[$key] : $default;
152+
return isset($this->server[$key]) ? $this->server[$key] : $default;
153153
}
154154

155155
/**

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

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

7171
default:
7272
throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
73-
};
73+
}
7474

7575
return $this;
7676
}

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
@@ -580,7 +580,7 @@ public static function camelize($id)
580580
*/
581581
public static function underscore($id)
582582
{
583-
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
583+
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id)));
584584
}
585585

586586
private function __clone()

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-
$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/Form/Tests/ChoiceList/AbstractChoiceListTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
abstract class AbstractChoiceListTest extends \PHPUnit_Framework_TestCase
1818
{
1919
/**
20-
* @var \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
20+
* @var \Symfony\Component\Form\ChoiceList\ChoiceListInterface
2121
*/
2222
protected $list;
2323

@@ -210,7 +210,7 @@ public function testGetValuesForChoicesEmpty()
210210
}
211211

212212
/**
213-
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
213+
* @return \Symfony\Component\Form\ChoiceList\ChoiceListInterface
214214
*/
215215
abstract protected function createChoiceList();
216216

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
@@ -191,7 +191,7 @@ public function registerCommands(Application $application)
191191
foreach ($finder as $file) {
192192
$ns = $prefix;
193193
if ($relativePath = $file->getRelativePath()) {
194-
$ns .= '\\'.strtr($relativePath, '/', '\\');
194+
$ns .= '\\'.str_replace('/', '\\', $relativePath);
195195
}
196196
$class = $ns.'\\'.$file->getBasename('.php');
197197
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
@@ -193,9 +193,8 @@ protected function fetch($db, $query, array $args = array())
193193
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
194194
}
195195
$stmt->execute();
196-
$return = $stmt->fetchAll(\PDO::FETCH_ASSOC);
197196

198-
return $return;
197+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
199198
}
200199

201200
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
}

0 commit comments

Comments
 (0)