Skip to content

Commit aaf180e

Browse files
committed
Merge branch '3.1'
* 3.1: [Console] SymfonyStyle: Align multi-line/very-long-line blocks [Console][DX] Fixed ambiguous error message when using a duplicate option shortcut Fix js comment in profiler [Ldap] Fixed issue with Entry password attribute containing array of values and made password attribute configurable [Serializer][#18837] adding a test [Cache] Drop counting hit/miss in ProxyAdapter [Serializer] AbstractObjectNormalizer: be sure that isAllowedAttribute is called [Serializer] ObjectNormalizer: add missing parameters
2 parents b9fec17 + f7caef4 commit aaf180e

File tree

3 files changed

+58
-6
lines changed

3 files changed

+58
-6
lines changed

Normalizer/AbstractObjectNormalizer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,7 @@ public function denormalize($data, $class, $format = null, array $context = arra
182182
$attribute = $this->nameConverter->denormalize($attribute);
183183
}
184184

185-
$allowed = $allowedAttributes === false || in_array($attribute, $allowedAttributes);
186-
$ignored = in_array($attribute, $this->ignoredAttributes);
187-
188-
if (!$allowed || $ignored) {
185+
if (($allowedAttributes !== false && !in_array($attribute, $allowedAttributes)) || !$this->isAllowedAttribute($class, $attribute, $format, $context)) {
189186
continue;
190187
}
191188

Normalizer/ObjectNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ protected function extractAttributes($object, $format = null, array $context = a
6868
$attributeName = lcfirst(substr($name, 2));
6969
}
7070

71-
if (null !== $attributeName && $this->isAllowedAttribute($object, $attributeName)) {
71+
if (null !== $attributeName && $this->isAllowedAttribute($object, $attributeName, $format, $context)) {
7272
$attributes[$attributeName] = true;
7373
}
7474
}
7575

7676
// properties
7777
foreach ($reflClass->getProperties(\ReflectionProperty::IS_PUBLIC) as $reflProperty) {
78-
if ($reflProperty->isStatic() || !$this->isAllowedAttribute($object, $reflProperty->name)) {
78+
if ($reflProperty->isStatic() || !$this->isAllowedAttribute($object, $reflProperty->name, $format, $context)) {
7979
continue;
8080
}
8181

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Normalizer;
13+
14+
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
15+
16+
class AbstractObjectNormalizerTest extends \PHPUnit_Framework_TestCase
17+
{
18+
public function testDenormalize()
19+
{
20+
$normalizer = new AbstractObjectNormalizerDummy();
21+
$normalizedData = $normalizer->denormalize(array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'), __NAMESPACE__.'\Dummy');
22+
23+
$this->assertSame('foo', $normalizedData->foo);
24+
$this->assertNull($normalizedData->bar);
25+
$this->assertSame('baz', $normalizedData->baz);
26+
}
27+
}
28+
29+
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
30+
{
31+
protected function extractAttributes($object, $format = null, array $context = array())
32+
{
33+
}
34+
35+
protected function getAttributeValue($object, $attribute, $format = null, array $context = array())
36+
{
37+
}
38+
39+
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
40+
{
41+
$object->$attribute = $value;
42+
}
43+
44+
protected function isAllowedAttribute($classOrObject, $attribute, $format = null, array $context = array())
45+
{
46+
return in_array($attribute, array('foo', 'baz'));
47+
}
48+
}
49+
50+
class Dummy
51+
{
52+
public $foo;
53+
public $bar;
54+
public $baz;
55+
}

0 commit comments

Comments
 (0)