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

Skip to content

Commit a5c0b8f

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: Typo fix [WebProfiler] Fixed sf-minitoolbar height [2.3] Static Code Analysis for Components [Serializer] Use $context['cache_key'] to enhance caching Fixed erroneous deprecation notice for extended Interfaces [Routing] cs fix 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 [Serializer] ObjectNormalizer: context can contain not serializable data
2 parents 25a379f + 4ed54a3 commit a5c0b8f

File tree

30 files changed

+249
-65
lines changed

30 files changed

+249
-65
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;
@@ -330,6 +331,44 @@ public function testValidateUniquenessWithUnrewoundArray()
330331
$this->assertNoViolation();
331332
}
332333

334+
/**
335+
* @dataProvider resultTypesProvider
336+
*/
337+
public function testValidateResultTypes($entity1, $result)
338+
{
339+
$constraint = new UniqueEntity(array(
340+
'message' => 'myMessage',
341+
'fields' => array('name'),
342+
'em' => self::EM_NAME,
343+
'repositoryMethod' => 'findByCustom',
344+
));
345+
346+
$repository = $this->createRepositoryMock();
347+
$repository->expects($this->once())
348+
->method('findByCustom')
349+
->will($this->returnValue($result))
350+
;
351+
$this->em = $this->createEntityManagerMock($repository);
352+
$this->registry = $this->createRegistryMock($this->em);
353+
$this->validator = $this->createValidator();
354+
$this->validator->initialize($this->context);
355+
356+
$this->validator->validate($entity1, $constraint);
357+
358+
$this->assertNoViolation();
359+
}
360+
361+
public function resultTypesProvider()
362+
{
363+
$entity = new SingleIntIdEntity(1, 'foo');
364+
365+
return array(
366+
array($entity, array($entity)),
367+
array($entity, new \ArrayIterator(array($entity))),
368+
array($entity, new ArrayCollection(array($entity))),
369+
);
370+
}
371+
333372
public function testAssociatedEntity()
334373
{
335374
$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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,24 +664,26 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
664664

665665
$dirs[] = dirname($r->getFileName()).'/../Resources/translations';
666666
}
667-
$overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations';
667+
$rootDir = $container->getParameter('kernel.root_dir');
668668
foreach ($container->getParameter('kernel.bundles') as $bundle => $class) {
669669
$reflection = new \ReflectionClass($class);
670670
if (is_dir($dir = dirname($reflection->getFileName()).'/Resources/translations')) {
671671
$dirs[] = $dir;
672672
}
673-
if (is_dir($dir = sprintf($overridePath, $bundle))) {
673+
if (is_dir($dir = $rootDir.sprintf('/Resources/%s/translations', $bundle))) {
674674
$dirs[] = $dir;
675675
}
676676
}
677+
677678
foreach ($config['paths'] as $dir) {
678679
if (is_dir($dir)) {
679680
$dirs[] = $dir;
680681
} else {
681682
throw new \UnexpectedValueException(sprintf('%s defined in translator.paths does not exist or is not a directory', $dir));
682683
}
683684
}
684-
if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) {
685+
686+
if (is_dir($dir = $rootDir.'/Resources/translations')) {
685687
$dirs[] = $dir;
686688
}
687689

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
background-color: #222;
66
border-top-left-radius: 4px;
77
bottom: 0;
8+
-webkit-box-sizing: border-box;
9+
-moz-box-sizing: border-box;
10+
box-sizing: border-box;
811
display: none;
9-
height: 30px;
10-
padding: 6px 6px 0;
12+
height: 36px;
13+
padding: 6px;
1114
position: fixed;
1215
right: 0;
1316
z-index: 99999;

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/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/Debug/DebugClassLoader.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,25 @@ public function loadClass($class)
169169
@trigger_error(sprintf('The %s class extends %s that is deprecated %s', $name, $parent->name, self::$deprecated[$parent->name]), E_USER_DEPRECATED);
170170
}
171171

172+
$parentInterfaces = array();
173+
$deprecatedInterfaces = array();
174+
if ($parent) {
175+
foreach ($parent->getInterfaceNames() as $interface) {
176+
$parentInterfaces[$interface] = 1;
177+
}
178+
}
179+
172180
foreach ($refl->getInterfaceNames() as $interface) {
173-
if (isset(self::$deprecated[$interface]) && strncmp($ns, $interface, $len) && !($parent && $parent->implementsInterface($interface))) {
181+
if (isset(self::$deprecated[$interface]) && strncmp($ns, $interface, $len)) {
182+
$deprecatedInterfaces[] = $interface;
183+
}
184+
foreach (class_implements($interface) as $interface) {
185+
$parentInterfaces[$interface] = 1;
186+
}
187+
}
188+
189+
foreach ($deprecatedInterfaces as $interface) {
190+
if (!isset($parentInterfaces[$interface])) {
174191
@trigger_error(sprintf('The %s %s %s that is deprecated %s', $name, $refl->isInterface() ? 'interface extends' : 'class implements', $interface, self::$deprecated[$interface]), E_USER_DEPRECATED);
175192
}
176193
}

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,28 @@ public function provideDeprecatedSuper()
199199
);
200200
}
201201

202+
public function testInterfaceExtendsDeprecatedInterface()
203+
{
204+
set_error_handler('var_dump', 0);
205+
$e = error_reporting(0);
206+
trigger_error('', E_USER_NOTICE);
207+
208+
class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true);
209+
210+
error_reporting($e);
211+
restore_error_handler();
212+
213+
$lastError = error_get_last();
214+
unset($lastError['file'], $lastError['line']);
215+
216+
$xError = array(
217+
'type' => E_USER_NOTICE,
218+
'message' => '',
219+
);
220+
221+
$this->assertSame($xError, $lastError);
222+
}
223+
202224
public function testDeprecatedSuperInSameNamespace()
203225
{
204226
set_error_handler('var_dump', 0);
@@ -285,6 +307,8 @@ public function findFile($class)
285307
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}');
286308
} elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) {
287309
eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}');
310+
} elseif ('Test\\'.__NAMESPACE__.'\NonDeprecatedInterfaceClass' === $class) {
311+
eval('namespace Test\\'.__NAMESPACE__.'; class NonDeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\NonDeprecatedInterface {}');
288312
} elseif ('Test\\'.__NAMESPACE__.'\Float' === $class) {
289313
eval('namespace Test\\'.__NAMESPACE__.'; class Float {}');
290314
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\Debug\Tests\Fixtures;
4+
5+
interface NonDeprecatedInterface extends DeprecatedInterface
6+
{
7+
}

src/Symfony/Component/DependencyInjection/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public static function camelize($id)
353353
*/
354354
public static function underscore($id)
355355
{
356-
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), strtr($id, '_', '.')));
356+
return strtolower(preg_replace(array('/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'), array('\\1_\\2', '\\1_\\2'), str_replace('_', '.', $id)));
357357
}
358358

359359
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
@@ -179,7 +179,7 @@ public function registerCommands(Application $application)
179179
foreach ($finder as $file) {
180180
$ns = $prefix;
181181
if ($relativePath = $file->getRelativePath()) {
182-
$ns .= '\\'.strtr($relativePath, '/', '\\');
182+
$ns .= '\\'.str_replace('/', '\\', $relativePath);
183183
}
184184
$class = $ns.'\\'.$file->getBasename('.php');
185185
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/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)