Skip to content

Commit 6eeae1b

Browse files
committed
Merge branch '2.8' into 3.2
* 2.8: Fix minor phpdoc mismatches with the code(detected by phan) [Asset] Starting slash should indicate no basePath wanted [Security] Fix phpdoc logout listener Add iconv extension to suggested dependencies Fix minor typo in the main README.md Allow Upper Case property names in ObjectNormalizer [EventDispatcher] fix: unwrap listeners for correct info
2 parents 47fedaf + dee868b commit 6eeae1b

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Encoder/XmlEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ private function appendNode(\DOMNode $parentNode, $data, $nodeName, $key = null)
471471
*/
472472
private function needsCdataWrapping($val)
473473
{
474-
return preg_match('/[<>&]/', $val);
474+
return 0 < preg_match('/[<>&]/', $val);
475475
}
476476

477477
/**

Normalizer/ObjectNormalizer.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ protected function extractAttributes($object, $format = null, array $context = a
6262

6363
if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) {
6464
// getters and hassers
65-
$attributeName = lcfirst(substr($name, 3));
65+
$attributeName = substr($name, 3);
66+
67+
if (!$reflClass->hasProperty($attributeName)) {
68+
$attributeName = lcfirst($attributeName);
69+
}
6670
} elseif (strpos($name, 'is') === 0) {
6771
// issers
68-
$attributeName = lcfirst(substr($name, 2));
72+
$attributeName = substr($name, 2);
73+
74+
if (!$reflClass->hasProperty($attributeName)) {
75+
$attributeName = lcfirst($attributeName);
76+
}
6977
}
7078

7179
if (null !== $attributeName && $this->isAllowedAttribute($object, $attributeName, $format, $context)) {

Tests/Normalizer/ObjectNormalizerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,11 @@ public function testNormalizeStatic()
509509
$this->assertEquals(array('foo' => 'K'), $this->normalizer->normalize(new ObjectWithStaticPropertiesAndMethods()));
510510
}
511511

512+
public function testNormalizeUpperCaseAttributes()
513+
{
514+
$this->assertEquals(array('Foo' => 'Foo', 'Bar' => 'BarBar'), $this->normalizer->normalize(new ObjectWithUpperCaseAttributeNames()));
515+
}
516+
512517
public function testNormalizeNotSerializableContext()
513518
{
514519
$objectDummy = new ObjectDummy();
@@ -911,3 +916,14 @@ class JsonNumber
911916
*/
912917
public $number;
913918
}
919+
920+
class ObjectWithUpperCaseAttributeNames
921+
{
922+
private $Foo = 'Foo';
923+
public $Bar = 'BarBar';
924+
925+
public function getFoo()
926+
{
927+
return $this->Foo;
928+
}
929+
}

0 commit comments

Comments
 (0)