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

Skip to content

Commit f5db539

Browse files
Merge branch '2.8' into 3.0
* 2.8: [Yaml] Fix tests on PHP 7.0.2 [FrameworkBundle] Don't log twice with the error handler [2.7] Workaround https://bugs.php.net/63206 [2.3] Workaround https://bugs.php.net/63206 Add closing parenthesis [Serializer] Unset object_to_populate after using it [Serializer] Allow to use proxies in object_to_populate Conflicts: src/Symfony/Component/Debug/ErrorHandler.php src/Symfony/Component/HttpFoundation/JsonResponse.php
2 parents a5c0b8f + 26979ed commit f5db539

File tree

12 files changed

+100
-22
lines changed

12 files changed

+100
-22
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ public function load(array $configs, ContainerBuilder $container)
137137
}
138138

139139
if ($container->getParameter('kernel.debug')) {
140+
$definition->replaceArgument(2, E_ALL & ~(E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR | E_RECOVERABLE_ERROR));
141+
140142
$loader->load('debug.xml');
141143

142144
$definition = $container->findDefinition('http_kernel');
@@ -148,7 +150,7 @@ public function load(array $configs, ContainerBuilder $container)
148150
$container->setDefinition('debug.event_dispatcher.parent', $definition);
149151
$container->setAlias('event_dispatcher', 'debug.event_dispatcher');
150152
} else {
151-
$definition->replaceArgument(2, E_COMPILE_ERROR | E_PARSE | E_ERROR | E_CORE_ERROR);
153+
$definition->replaceArgument(1, null);
152154
}
153155

154156
$this->addClassesToCompile(array(

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ErrorHandler
9090

9191
private $loggedTraces = array();
9292
private $isRecursive = 0;
93+
private $isRoot = false;
9394
private $exceptionHandler;
9495
private $bootstrappingLogger;
9596

@@ -117,7 +118,12 @@ public static function register(self $handler = null, $replace = true)
117118
$handler = new static();
118119
}
119120

120-
$prev = set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
121+
if (null === $prev = set_error_handler(array($handler, 'handleError'))) {
122+
restore_error_handler();
123+
// Specifying the error types earlier would expose us to https://bugs.php.net/63206
124+
set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
125+
$handler->isRoot = true;
126+
}
121127

122128
if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
123129
$handler = $prev[0];
@@ -325,12 +331,16 @@ public function screamAt($levels, $replace = false)
325331
private function reRegister($prev)
326332
{
327333
if ($prev !== $this->thrownErrors | $this->loggedErrors) {
328-
$handler = set_error_handler('var_dump', 0);
334+
$handler = set_error_handler('var_dump');
329335
$handler = is_array($handler) ? $handler[0] : null;
330336
restore_error_handler();
331337
if ($handler === $this) {
332338
restore_error_handler();
333-
set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
339+
if ($this->isRoot) {
340+
set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
341+
} else {
342+
set_error_handler(array($this, 'handleError'));
343+
}
334344
}
335345
}
336346
}
@@ -552,7 +562,7 @@ public static function handleFatalError(array $error = null)
552562

553563
self::$reservedMemory = null;
554564

555-
$handler = set_error_handler('var_dump', 0);
565+
$handler = set_error_handler('var_dump');
556566
$handler = is_array($handler) ? $handler[0] : null;
557567
restore_error_handler();
558568

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testClassAlias()
171171
*/
172172
public function testDeprecatedSuper($class, $super, $type)
173173
{
174-
set_error_handler('var_dump', 0);
174+
set_error_handler(function() { return false; });
175175
$e = error_reporting(0);
176176
trigger_error('', E_USER_DEPRECATED);
177177

@@ -201,7 +201,7 @@ public function provideDeprecatedSuper()
201201

202202
public function testInterfaceExtendsDeprecatedInterface()
203203
{
204-
set_error_handler('var_dump', 0);
204+
set_error_handler(function() { return false; });
205205
$e = error_reporting(0);
206206
trigger_error('', E_USER_NOTICE);
207207

@@ -223,7 +223,7 @@ class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true);
223223

224224
public function testDeprecatedSuperInSameNamespace()
225225
{
226-
set_error_handler('var_dump', 0);
226+
set_error_handler(function() { return false; });
227227
$e = error_reporting(0);
228228
trigger_error('', E_USER_NOTICE);
229229

@@ -249,7 +249,7 @@ public function testReservedForPhp7()
249249
$this->markTestSkipped('PHP7 already prevents using reserved names.');
250250
}
251251

252-
set_error_handler('var_dump', 0);
252+
set_error_handler(function() { return false; });
253253
$e = error_reporting(0);
254254
trigger_error('', E_USER_NOTICE);
255255

src/Symfony/Component/EventDispatcher/EventSubscriberInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface EventSubscriberInterface
3838
*
3939
* * array('eventName' => 'methodName')
4040
* * array('eventName' => array('methodName', $priority))
41-
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
41+
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')))
4242
*
4343
* @return array The event names to listen to
4444
*/

src/Symfony/Component/Filesystem/LockHandler.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ public function lock($blocking = false)
6868
return true;
6969
}
7070

71-
// Silence both userland and native PHP error handlers
72-
$errorLevel = error_reporting(0);
73-
set_error_handler('var_dump', 0);
71+
// Silence error reporting
72+
set_error_handler(function() {});
7473

7574
if (!$this->handle = fopen($this->file, 'r')) {
7675
if ($this->handle = fopen($this->file, 'x')) {
@@ -81,7 +80,6 @@ public function lock($blocking = false)
8180
}
8281
}
8382
restore_error_handler();
84-
error_reporting($errorLevel);
8583

8684
if (!$this->handle) {
8785
$error = error_get_last();

src/Symfony/Component/HttpKernel/EventListener/DebugHandlersListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function configure(Event $event = null)
6767
}
6868
$this->firstCall = false;
6969
if ($this->logger || null !== $this->throwAt) {
70-
$handler = set_error_handler('var_dump', 0);
70+
$handler = set_error_handler('var_dump');
7171
$handler = is_array($handler) ? $handler[0] : null;
7272
restore_error_handler();
7373
if ($handler instanceof ErrorHandler) {

src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ protected function prepareForDenormalization($data)
224224
* Instantiates an object using constructor parameters when needed.
225225
*
226226
* This method also allows to denormalize data into an existing object if
227-
* it is present in the context with the object_to_populate key.
227+
* it is present in the context with the object_to_populate. This object
228+
* is removed from the context before being returned to avoid side effects
229+
* when recursively normalizing an object graph.
228230
*
229231
* @param array $data
230232
* @param string $class
@@ -241,9 +243,12 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
241243
if (
242244
isset($context['object_to_populate']) &&
243245
is_object($context['object_to_populate']) &&
244-
$class === get_class($context['object_to_populate'])
246+
$context['object_to_populate'] instanceof $class
245247
) {
246-
return $context['object_to_populate'];
248+
$object = $context['object_to_populate'];
249+
unset($context['object_to_populate']);
250+
251+
return $object;
247252
}
248253

249254
$constructor = $reflectionClass->getConstructor();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Kévin Dunglas <[email protected]>
16+
*/
17+
class ProxyDummy extends ToBeProxyfiedDummy
18+
{
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Kévin Dunglas <[email protected]>
16+
*/
17+
class ToBeProxyfiedDummy
18+
{
19+
private $foo;
20+
21+
public function setFoo($foo)
22+
{
23+
$this->foo = $foo;
24+
}
25+
26+
public function getFoo()
27+
{
28+
return $this->foo;
29+
}
30+
}

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractNormalizerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
66
use Symfony\Component\Serializer\Mapping\ClassMetadata;
77
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
8+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
89
use Symfony\Component\Serializer\Tests\Fixtures\AbstractNormalizerDummy;
10+
use Symfony\Component\Serializer\Tests\Fixtures\ProxyDummy;
911

1012
/**
1113
* Provides a dummy Normalizer which extends the AbstractNormalizer.
@@ -88,4 +90,16 @@ public function testGetAllowedAttributesAsObjects()
8890
$result = $this->normalizer->getAllowedAttributes('c', array('groups' => array('other')), false);
8991
$this->assertEquals(array($a3, $a4), $result);
9092
}
93+
94+
public function testObjectToPopulateWithProxy()
95+
{
96+
$proxyDummy = new ProxyDummy();
97+
98+
$context = array('object_to_populate' => $proxyDummy);
99+
100+
$normalizer = new ObjectNormalizer();
101+
$normalizer->denormalize(array('foo' => 'bar'), 'Symfony\Component\Serializer\Tests\Fixtures\ToBeProxyfiedDummy', null, $context);
102+
103+
$this->assertSame('bar', $proxyDummy->getFoo());
104+
}
91105
}

src/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ yaml: |
515515
php: |
516516
array(
517517
'canonical' => 12345,
518-
'decimal' => 12345,
518+
'decimal' => 12345.0,
519519
'octal' => 014,
520520
'hexadecimal' => 0xC
521521
)
@@ -1538,7 +1538,7 @@ yaml: |
15381538
php: |
15391539
array(
15401540
'canonical' => 12345,
1541-
'decimal' => 12345,
1541+
'decimal' => 12345.0,
15421542
'octal' => 12,
15431543
'hexadecimal' => 12
15441544
)

src/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ php: |
182182
array(
183183
'zero' => 0,
184184
'simple' => 12,
185-
'one-thousand' => 1000,
186-
'negative one-thousand' => -1000
185+
'one-thousand' => 1000.0,
186+
'negative one-thousand' => -1000.0
187187
)
188188
---
189189
test: Integers as Map Keys

0 commit comments

Comments
 (0)