Skip to content

Commit e3ccdaf

Browse files
Merge branch '3.4'
* 3.4: Deprecate support for stacked errors fixed tests [HttpFoundation] Find the original request protocol version fixed CS Add support for microseconds in Stopwatch Preserve HttpOnly value when deserializing a header add minimum and maximum amount of pixels to Image validator fixed CHANGELOG [DX] [TwigBundle] Enhance the new exception page design [BrowserKit] Emulate back/forward browser navigation Fix deprecated message [Component][Serializer][Normalizer] : Deal it with Has Method for the Normalizer/Denormalizer [Validator] improve the changelog [FrameworkBundle] Wire inner translator [FrameworkBundle][HttpKernel] Move addcachearmer, addcacheclearer compiler pass [FrameworkBundle][Translation] Move translation compiler pass
2 parents ae44630 + 11cc001 commit e3ccdaf

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

Normalizer/GetSetMethodNormalizer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ private function isGetMethod(\ReflectionMethod $method)
8787
!$method->isStatic() &&
8888
(
8989
((0 === strpos($method->name, 'get') && 3 < $methodLength) ||
90-
(0 === strpos($method->name, 'is') && 2 < $methodLength)) &&
90+
(0 === strpos($method->name, 'is') && 2 < $methodLength) ||
91+
(0 === strpos($method->name, 'has') && 3 < $methodLength)) &&
9192
0 === $method->getNumberOfRequiredParameters()
9293
)
9394
;
@@ -133,6 +134,11 @@ protected function getAttributeValue($object, $attribute, $format = null, array
133134
if (is_callable(array($object, $isser))) {
134135
return $object->$isser();
135136
}
137+
138+
$haser = 'has'.$ucfirsted;
139+
if (is_callable(array($object, $haser))) {
140+
return $object->$haser();
141+
}
136142
}
137143

138144
/**

Tests/Normalizer/GetSetMethodNormalizerTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,23 @@ public function testPrivateSetter()
491491
$this->assertEquals('bar', $obj->getFoo());
492492
}
493493

494+
public function testHasGetterDenormalize()
495+
{
496+
$obj = $this->normalizer->denormalize(array('foo' => true), ObjectWithHasGetterDummy::class);
497+
$this->assertTrue($obj->hasFoo());
498+
}
499+
500+
public function testHasGetterNormalize()
501+
{
502+
$obj = new ObjectWithHasGetterDummy();
503+
$obj->setFoo(true);
504+
505+
$this->assertEquals(
506+
array('foo' => true),
507+
$this->normalizer->normalize($obj, 'any')
508+
);
509+
}
510+
494511
public function testMaxDepth()
495512
{
496513
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
@@ -801,3 +818,18 @@ public static function setFoo($foo)
801818
self::$foo = $foo;
802819
}
803820
}
821+
822+
class ObjectWithHasGetterDummy
823+
{
824+
private $foo;
825+
826+
public function setFoo($foo)
827+
{
828+
$this->foo = $foo;
829+
}
830+
831+
public function hasFoo()
832+
{
833+
return $this->foo;
834+
}
835+
}

0 commit comments

Comments
 (0)