Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0d7c403

Browse filesBrowse files
committed
[Form] fixed camelization problem when looking for a method (getCreated_at -> getCreatedAt)
1 parent 3b1e833 commit 0d7c403
Copy full SHA for 0d7c403

File tree

Expand file treeCollapse file tree

1 file changed

+7
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-3
lines changed

‎src/Symfony/Component/Form/Field.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Field.php
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,10 @@ protected function updatePropertyPath(&$objectOrArray, PropertyPath $propertyPat
543543
*/
544544
protected function readProperty($object, PropertyPath $propertyPath)
545545
{
546+
$camelizer = function ($path) {
547+
return preg_replace(array('/(^|_)+(.)/e', '/\.(.)/e'), array("strtoupper('\\2')", "'_'.strtoupper('\\1')"), $path);
548+
};
549+
546550
if ($propertyPath->isIndex()) {
547551
if (!$object instanceof \ArrayAccess) {
548552
throw new InvalidPropertyException(sprintf('Index "%s" cannot be read from object of type "%s" because it doesn\'t implement \ArrayAccess', $propertyPath->getCurrent(), get_class($object)));
@@ -551,8 +555,8 @@ protected function readProperty($object, PropertyPath $propertyPath)
551555
return $object[$propertyPath->getCurrent()];
552556
} else {
553557
$reflClass = new \ReflectionClass($object);
554-
$getter = 'get'.ucfirst($propertyPath->getCurrent());
555-
$isser = 'is'.ucfirst($propertyPath->getCurrent());
558+
$getter = 'get'.$camelizer($propertyPath->getCurrent());
559+
$isser = 'is'.$camelizer($propertyPath->getCurrent());
556560
$property = $propertyPath->getCurrent();
557561

558562
if ($reflClass->hasMethod($getter)) {
@@ -637,4 +641,4 @@ public function renderErrors()
637641

638642
return $html;
639643
}
640-
}
644+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.