8000 [Serializer] Remove unused code · symfony/symfony@61b8494 · GitHub
[go: up one dir, main page]

Skip to content

Commit 61b8494

Browse files
dunglasfabpot
authored andcommitted
[Serializer] Remove unused code
1 parent 0bacaba commit 61b8494

File tree

1 file changed

+7
-36
lines changed

1 file changed

+7
-36
lines changed

src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\Serializer\Normalizer;
1313

14-
use Symfony\Component\Serializer\Exception\RuntimeException;
15-
1614
/**
1715
* Converts between objects with getter and setter methods and arrays.
1816
*
@@ -36,39 +34,7 @@
3634
*/
3735
class GetSetMethodNormalizer extends Ab 8000 stractObjectNormalizer
3836
{
39-
/**
40-
* {@inheritdoc}
41-
*
42-
* @throws RuntimeException
43-
*/
44-
public function denormalize($data, $class, $format = null, array $context = array())
45-
{
46-
$allowedAttributes = $this->getAllowedAttributes($class, $context, true);
47-
$normalizedData = $this->prepareForDenormalization($data);
48-
49-
$reflectionClass = new \ReflectionClass($class);
50-
$object = $this->instantiateObject($normalizedData, $class, $context, $reflectionClass, $allowedAttributes);
51-
52-
$classMethods = get_class_methods($object);
53-
foreach ($normalizedData as $attribute => $value) {
54-
if ($this->nameConverter) {
55-
$attribute = $this->nameConverter->denormalize($attribute);
56-
}
57-
58-
$allowed = $allowedAttributes === false || in_array($attribute, $allowedAttributes);
59-
$ignored = in_array($attribute, $this->ignoredAttributes);
60-
61-
if ($allowed && !$ignored) {
62-
$setter = 'set'.ucfirst($attribute);
63-
64-
if (in_array($setter, $classMethods) && !$reflectionClass->getMethod($setter)->isStatic()) {
65-
$object->$setter($value);
66-
}
67-
}
68-
}
69-
70-
return $object;
71-
}
37+
private static $setterAccessibleCache = array();
7238

7339
/**
7440
* {@inheritdoc}
@@ -175,8 +141,13 @@ protected function getAttributeValue($object, $attribute, $format = null, array
175141
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array())
176142
{
177143
$setter = 'set'.ucfirst($attribute);
144+
$key = get_class($object).':'.$setter;
145+
146+
if (!isset(self::$setterAccessibleCache[$key])) {
147+
self::$setterAccessibleCache[$key] = is_callable(array($object, $setter)) && !(new \ReflectionMethod($object, $setter))->isStatic();
148+
}
178149

179-
if (is_callable(array($object, $setter))) {
150+
if (self::$setterAccessibleCache[$key]) {
180151
$object->$setter($value);
181152
}
182153
}

0 commit comments

Comments
 (0)
0