8000 Allow Upper Case property names in ObjectNormalizer by insekticid · Pull Request #22550 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Allow Upper Case property names in ObjectNormalizer #22550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump 8000 to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,22 @@ private function extractAttributes($object)

if (0 === strpos($name, 'get') || 0 === strpos($name, 'has')) {
// getters and hassers
$attributes[lcfirst(substr($name, 3))] = true;
$propertyName = substr($name, 3);

if (!$reflClass->hasProperty($propertyName)) {
$propertyName = lcfirst($propertyName);
}

$attributes[$propertyName] = true;
} elseif (strpos($name, 'is') === 0) {
// issers
$attributes[lcfirst(substr($name, 2))] = true;
$propertyName = substr($name, 2);

if (!$reflClass->hasProperty($propertyName)) {
$propertyName = lcfirst($propertyName);
}

$attributes[$propertyName] = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ public function testNormalizeStatic()
$this->assertEquals(array('foo' => 'K'), $this->normalizer->normalize(new ObjectWithStaticPropertiesAndMethods()));
}

public function testNormalizeUpperCaseAttributes()
{
$this->assertEquals(array('Foo' => 'Foo', 'Bar' => 'BarBar'), $this->normalizer->normalize(new ObjectWithUpperCaseAttributeNames()));
}

public function testNormalizeNotSerializableContext()
{
$objectDummy = new ObjectDummy();
Expand Down Expand Up @@ -662,3 +667,14 @@ public static function getBaz()
return 'L';
}
}

class ObjectWithUpperCaseAttributeNames
{
private $Foo = 'Foo';
public $Bar = 'BarBar';

public function getFoo()
{
return $this->Foo;
}
}
0