From 4eae4163284a864828843a84a71f16dd0383dedf Mon Sep 17 00:00:00 2001 From: Marcin Chwedziak Date: Sun, 23 Feb 2014 00:56:53 +0100 Subject: [PATCH 1/4] support is.* in GetSetMethodNormalizer --- CHANGELOG-2.4.md | 4 ++ .../Normalizer/GetSetMethodNormalizer.php | 12 +++-- .../Normalizer/GetSetMethodNormalizerTest.php | 50 +++++++++++++------ 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/CHANGELOG-2.4.md b/CHANGELOG-2.4.md index 2493c202cb6d..a63f368e0878 100644 --- a/CHANGELOG-2.4.md +++ b/CHANGELOG-2.4.md @@ -7,6 +7,10 @@ in 2.4 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v2.4.0...v2.4.1 +* 2.4.3 (2014-02-23) + + * feature #10297 [Serializer] added support for is.* methods in GetSetMethodNormalizer (tiraeth) + * 2.4.2 (2014-02-12) * bug #10215 [Routing] reduced recursion in dumper (arnaud-lb) diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 1b1a5f568874..5f5cf05b4433 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -88,7 +88,7 @@ public function normalize($object, $format = null, array $context = array()) $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { - $attributeName = lcfirst(substr($method->name, 3)); + $attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3)); if (in_array($attributeName, $this->ignoredAttributes)) { continue; @@ -211,17 +211,19 @@ private function supports($class) } /** - * Checks if a method's name is get.* and can be called without parameters. + * Checks if a method's name is get.* or is.*, and can be called without parameters. * * @param \ReflectionMethod $method the method to check * - * @return Boolean whether the method is a getter. + * @return Boolean whether the method is a getter or boolean getter. */ private function isGetMethod(\ReflectionMethod $method) { return ( - 0 === strpos($method->name, 'get') && - 3 < strlen($method->name) && + ((0 === strpos($method->name, 'get') && + 3 < strlen($method->name)) || + (0 === strpos($method->name, 'is') && + 2 < strlen($method->name))) && 0 === $method->getNumberOfRequiredParameters() ); } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index f3bf9694d206..df236abe9797 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -26,9 +26,10 @@ public function testNormalize() $obj = new GetSetDummy(); $obj->setFoo('foo'); $obj->setBar('bar'); + $obj->setBaz(true); $obj->setCamelCase('camelcase'); $this->assertEquals( - array('foo' => 'foo', 'bar' => 'bar', 'fooBar' => 'foobar', 'camelCase' => 'camelcase'), + array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar', 'camelCase' => 'camelcase'), $this->normalizer->normalize($obj, 'any') ); } @@ -36,12 +37,13 @@ public function testNormalize() public function testDenormalize() { $obj = $this->normalizer->denormalize( - array('foo' => 'foo', 'bar' => 'bar', 'fooBar' => 'foobar'), + array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'), __NAMESPACE__.'\GetSetDummy', 'any' ); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); + $this->assertEquals(true, $obj->isBaz()); } public function testDenormalizeOnCamelCaseFormat() @@ -80,10 +82,11 @@ public function attributeProvider() public function testConstructorDenormalize() { $obj = $this->normalizer->denormalize( - array('foo' => 'foo', 'bar' => 'bar', 'fooBar' => 'foobar'), + array('foo' => 'foo', 'bar' => 'bar', 'baz' => true, 'fooBar' => 'foobar'), __NAMESPACE__.'\GetConstructorDummy', 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); + $this->assertEquals(true, $obj->isBaz()); } /** @@ -93,7 +96,7 @@ public function testCallbacks($callbacks, $value, $result, $message) { $this->normalizer->setCallbacks($callbacks); - $obj = new GetConstructorDummy('', $value); + $obj = new GetConstructorDummy('', $value, true); $this->assertEquals( $result, @@ -109,18 +112,19 @@ public function testUncallableCallbacks() { $this->normalizer->setCallbacks(array('bar' => null)); - $obj = new GetConstructorDummy('baz', 'quux'); + $obj = new GetConstructorDummy('baz', 'quux', true); $this->normalizer->normalize($obj, 'any'); } public function testIgnoredAttributes() { - $this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'camelCase')); + $this->normalizer->setIgnoredAttributes(array('foo', 'bar', 'baz', 'camelCase')); $obj = new GetSetDummy(); $obj->setFoo('foo'); $obj->setBar('bar'); + $obj->setBaz(true); $this->assertEquals( array('fooBar' => 'foobar'), @@ -138,7 +142,7 @@ public function provideCallbacks() }, ), 'baz', - array('foo' => '', 'bar' => 'baz'), + array('foo' => '', 'bar' => 'baz', 'baz' => true), 'Change a string', ), array( @@ -148,7 +152,7 @@ public function provideCallbacks() }, ), 'baz', - array('foo' => '', 'bar' => null), + array('foo' => '', 'bar' => null, 'baz' => true), 'Null an item' ), array( @@ -158,7 +162,7 @@ public function provideCallbacks() }, ), new \DateTime('2011-09-10 06:30:00'), - array('foo' => '', 'bar' => '10-09-2011 06:30:00'), + array('foo' => '', 'bar' => '10-09-2011 06:30:00', 'baz' => true), 'Format a date', ), array( @@ -172,8 +176,8 @@ public function provideCallbacks() return $foos; }, ), - array(new GetConstructorDummy('baz', ''), new GetConstructorDummy('quux', '')), - array('foo' => '', 'bar' => 'bazquux'), + array(new GetConstructorDummy('baz', '', false), new GetConstructorDummy('quux', '', false)), + array('foo' => '', 'bar' => 'bazquux', 'baz' => true), 'Collect a property', ), array( @@ -182,8 +186,8 @@ public function provideCallbacks() return count($bars); }, ), - array(new GetConstructorDummy('baz', ''), new GetConstructorDummy('quux', '')), - array('foo' => '', 'bar' => 2), + array(new GetConstructorDummy('baz', '', false), new GetConstructorDummy('quux', '', false)), + array('foo' => '', 'bar' => 2, 'baz' => true), 'Count a property', ), ); @@ -194,6 +198,7 @@ class GetSetDummy { protected $foo; private $bar; + private $baz; protected $camelCase; public function getFoo() @@ -216,6 +221,16 @@ public function setBar($bar) $this->bar = $bar; } + public function isBaz() + { + return $this->baz; + } + + public function setBaz($baz) + { + $this->baz = $baz; + } + public function getFooBar() { return $this->foo.$this->bar; @@ -241,11 +256,13 @@ class GetConstructorDummy { protected $foo; private $bar; + private $baz; - public function __construct($foo, $bar) + public function __construct($foo, $bar, $baz) { $this->foo = $foo; $this->bar = $bar; + $this->baz = $baz; } public function getFoo() @@ -258,6 +275,11 @@ public function getBar() return $this->bar; } + public function isBaz() + { + return $this->baz; + } + public function otherMethod() { throw new \RuntimeException("Dummy::otherMethod() should not be called"); From 2999fd166db06f2bc12d4886657380817a93892d Mon Sep 17 00:00:00 2001 From: Marcin Chwedziak Date: Mon, 24 Feb 2014 10:51:28 +0100 Subject: [PATCH 2/4] #10314 cleanup --- CHANGELOG-2.4.md | 4 ---- .../Serializer/Normalizer/GetSetMethodNormalizer.php | 8 ++++---- .../Tests/Normalizer/GetSetMethodNormalizerTest.php | 4 ++-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CHANGELOG-2.4.md b/CHANGELOG-2.4.md index a63f368e0878..2493c202cb6d 100644 --- a/CHANGELOG-2.4.md +++ b/CHANGELOG-2.4.md @@ -7,10 +7,6 @@ in 2.4 minor versions. To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v2.4.0...v2.4.1 -* 2.4.3 (2014-02-23) - - * feature #10297 [Serializer] added support for is.* methods in GetSetMethodNormalizer (tiraeth) - * 2.4.2 (2014-02-12) * bug #10215 [Routing] reduced recursion in dumper (arnaud-lb) diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 5f5cf05b4433..1632fa4446f4 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -219,11 +219,11 @@ private function supports($class) */ private function isGetMethod(\ReflectionMethod $method) { + $methodLength = strlen($method->name); + return ( - ((0 === strpos($method->name, 'get') && - 3 < strlen($method->name)) || - (0 === strpos($method->name, 'is') && - 2 < strlen($method->name))) && + ((0 === strpos($method->name, 'get') && 3 < $methodLength) || + (0 === strpos($method->name, 'is') && 2 < $methodLength)) && 0 === $method->getNumberOfRequiredParameters() ); } diff --git a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php index df236abe9797..0e6934359e19 100644 --- a/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php +++ b/src/Symfony/Component/Serializer/Tests/Normalizer/GetSetMethodNormalizerTest.php @@ -43,7 +43,7 @@ public function testDenormalize() ); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); - $this->assertEquals(true, $obj->isBaz()); + $this->assertTrue($obj->isBaz()); } public function testDenormalizeOnCamelCaseFormat() @@ -86,7 +86,7 @@ public function testConstructorDenormalize() __NAMESPACE__.'\GetConstructorDummy', 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); - $this->assertEquals(true, $obj->isBaz()); + $this->assertTrue($obj->isBaz()); } /** From e7be60718673fcc8109ba28cdfc71655c5e32f69 Mon Sep 17 00:00:00 2001 From: Marcin Chwedziak Date: Mon, 24 Feb 2014 17:36:29 +0100 Subject: [PATCH 3/4] fabbot patch --- .../Component/Serializer/Normalizer/GetSetMethodNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php index 1632fa4446f4..f24442680baf 100644 --- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php @@ -220,7 +220,7 @@ private function supports($class) private function isGetMethod(\ReflectionMethod $method) { $methodLength = strlen($method->name); - + return ( ((0 === strpos($method->name, 'get') && 3 < $methodLength) || (0 === strpos($method->name, 'is') && 2 < $methodLength)) && From 7d38bdf06f5127e4fcdf870fec54ab3d4017370c Mon Sep 17 00:00:00 2001 From: Marcin Chwedziak Date: Mon, 24 Feb 2014 17:58:28 +0100 Subject: [PATCH 4/4] Updated CHANGELOG, assumed that it will be 2.5.0 --- src/Symfony/Component/Serializer/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Symfony/Component/Serializer/CHANGELOG.md b/src/Symfony/Component/Serializer/CHANGELOG.md index 66081baa0585..d5502b062f47 100644 --- a/src/Symfony/Component/Serializer/CHANGELOG.md +++ b/src/Symfony/Component/Serializer/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +2.5.0 +----- + + * added support for `is.*` getters in `GetSetMethodNormalizer` + 2.4.0 ----- pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy