8000 bug #18261 [PropertyAccess] Fix isPropertyWritable not using the refl… · symfony/symfony@241a725 · GitHub
[go: up one dir, main page]

Skip to content

Commit 241a725

Browse files
bug #18261 [PropertyAccess] Fix isPropertyWritable not using the reflection cache (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [PropertyAccess] Fix isPropertyWritable not using the reflection cache | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - While merging 2.3 into 2.7, I noticed that isPropertyWritable did not make use of the reflection cache of getWriteAccessInfo. This PR fixes it. Commits ------- 8a52fcd [PropertyAccess] Fix isPropertyWritable not using the reflection cache
2 parents 86c0a17 + 8a52fcd commit 241a725

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -748,30 +748,13 @@ private function isPropertyWritable($object, $property)
748748
return false;
749749
}
750750

751-
$reflClass = new \ReflectionClass($object);
752-
753-
$camelized = $this->camelize($property);
754-
$setter = 'set'.$camelized;
755-
$getsetter = lcfirst($camelized); // jQuery style, e.g. read: last(), write: last($item)
756-
$classHasProperty = $reflClass->hasProperty($property);
757-
758-
if ($this->isMethodAccessible($reflClass, $setter, 1)
759-
|| $this->isMethodAccessible($reflClass, $getsetter, 1)
760-
|| $this->isMethodAccessible($reflClass, '__set', 2)
761-
|| ($classHasProperty && $reflClass->getProperty($property)->isPublic())
762-
|| (!$classHasProperty && property_exists($object, $property))
763-
|| ($this->magicCall && $this->isMethodAccessible($reflClass, '__call', 2))) {
764-
return true;
765-
}
751+
$access = $this->getWriteAccessInfo(get_class($object), $property, array());
766752

767-
$singulars = (array) StringUtil::singularify($camelized);
768-
769-
// Any of the two methods is required, but not yet known
770-
if (null !== $this->findAdderAndRemover($reflClass, $singulars)) {
771-
return true;
772-
}
773-
774-
return false;
753+
return self::ACCESS_TYPE_METHOD === $access[self::ACCESS_TYPE]
754+
|| self::ACCESS_TYPE_PROPERTY === $access[self::ACCESS_TYPE]
755+
|| self::ACCESS_TYPE_ADDER_AND_REMOVER === $access[self::ACCESS_TYPE]
756+
|| (!$access[self::ACCESS_HAS_PROPERTY] && property_exists($object, $property))
757+
|| self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE];
775758
}
776759

777760
/**
@@ -783,7 +766,7 @@ private function isPropertyWritable($object, $property)
783766
*/
784767
private function camelize($string)
785768
{
786-
return strtr(ucwords(strtr($string, array('_' => ' '))), array(' ' => ''));
769+
return str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
787770
}
788771

789772
/**

0 commit comments

Comments
 (0)
0