class GetSetMethodNormalizer extends AbstractObjectNormalizer
{
private static $setterAccessibleCache = array();
+ private $cache = array();
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null)
{
- return parent::supportsNormalization($data, $format) && $this->supports(get_class($data));
+ return parent::supportsNormalization($data, $format) && (isset($this->cache[$type = \get_class($data)]) ? $this->cache[$type] : $this->cache[$type] = $this->supports($type));
}
/**
*/
public function supportsDenormalization($data, $type, $format = null)
{
- return parent::supportsDenormalization($data, $type, $format) && $this->supports($type);
+ return parent::supportsDenormalization($data, $type, $format) && (isset($this->cache[$type]) ? $this->cache[$type] : $this->cache[$type] = $this->supports($type));
}
/**
/**
* Checks if a method's name is get.* or is.*, and can be called without parameters.
*
- * @param \ReflectionMethod $method the method to check
- *
* @return bool whether the method is a getter or boolean getter
*/
private function isGetMethod(\ReflectionMethod $method)
{
- $methodLength = strlen($method->name);
+ $methodLength = \strlen($method->name);
return
!$method->isStatic() &&
(
((0 === strpos($method->name, 'get') && 3 < $methodLength) ||
- (0 === strpos($method->name, 'is') && 2 < $methodLength)) &&
+ (0 === strpos($method->name, 'is') && 2 < $methodLength) ||
+ (0 === strpos($method->name, 'has') && 3 < $methodLength)) &&
0 === $method->getNumberOfRequiredParameters()
)
;
$ucfirsted = ucfirst($attribute);
$getter = 'get'.$ucfirsted;
- if (is_callable(array($object, $getter))) {
+ if (\is_callable(array($object, $getter))) {
return $object->$getter();
}
$isser = 'is'.$ucfirsted;
- if (is_callable(array($object, $isser))) {
+ if (\is_callable(array($object, $isser))) {
return $object->$isser();
}
+
+ $haser = 'has'.$ucfirsted;
+ if (\is_callable(array($object, $haser))) {
+ return $object->$haser();
+ }
}
/**
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
{
$setter = 'set'.ucfirst($attribute);
- $key = get_class($object).':'.$setter;
+ $key = \get_class($object).':'.$setter;
if (!isset(self::$setterAccessibleCache[$key])) {
- self::$setterAccessibleCache[$key] = is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic();
+ self::$setterAccessibleCache[$key] = \is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic();
}
if (self::$setterAccessibleCache[$key]) {