[PropertyAccess] Fix isPropertyWritable not using the reflection cache
This commit is contained in:
parent
86c0a17721
commit
8a52fcdbff
@ -748,30 +748,13 @@ class PropertyAccessor implements PropertyAccessorInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reflClass = new \ReflectionClass($object);
|
$access = $this->getWriteAccessInfo(get_class($object), $property, array());
|
||||||
|
|
||||||
$camelized = $this->camelize($property);
|
return self::ACCESS_TYPE_METHOD === $access[self::ACCESS_TYPE]
|
||||||
$setter = 'set'.$camelized;
|
|| self::ACCESS_TYPE_PROPERTY === $access[self::ACCESS_TYPE]
|
||||||
$getsetter = lcfirst($camelized); // jQuery style, e.g. read: last(), write: last($item)
|
|| self::ACCESS_TYPE_ADDER_AND_REMOVER === $access[self::ACCESS_TYPE]
|
||||||
$classHasProperty = $reflClass->hasProperty($property);
|
|| (!$access[self::ACCESS_HAS_PROPERTY] && property_exists($object, $property))
|
||||||
|
|| self::ACCESS_TYPE_MAGIC === $access[self::ACCESS_TYPE];
|
||||||
if ($this->isMethodAccessible($reflClass, $setter, 1)
|
|
||||||
|| $this->isMethodAccessible($reflClass, $getsetter, 1)
|
|
||||||
|| $this->isMethodAccessible($reflClass, '__set', 2)
|
|
||||||
|| ($classHasProperty && $reflClass->getProperty($property)->isPublic())
|
|
||||||
|| (!$classHasProperty && property_exists($object, $property))
|
|
||||||
|| ($this->magicCall && $this->isMethodAccessible($reflClass, '__call', 2))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$singulars = (array) StringUtil::singularify($camelized);
|
|
||||||
|
|
||||||
// Any of the two methods is required, but not yet known
|
|
||||||
if (null !== $this->findAdderAndRemover($reflClass, $singulars)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -783,7 +766,7 @@ class PropertyAccessor implements PropertyAccessorInterface
|
|||||||
*/
|
*/
|
||||||
private function camelize($string)
|
private function camelize($string)
|
||||||
{
|
{
|
||||||
return strtr(ucwords(strtr($string, array('_' => ' '))), array(' ' => ''));
|
return str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user