From e69c6bd7bab884e17d3af9a952774c41b38a7875 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 6 Jun 2016 13:19:45 +0200 Subject: [PATCH 1/5] Add argument to PropertyAccess::createPropertyAccessor Remove extra arg on PropertyAccessBuilder --- .../PropertyAccess/PropertyAccess.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccess.php b/src/Symfony/Component/PropertyAccess/PropertyAccess.php index 6c9bb423d021f..aad11d7a019a1 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccess.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccess.php @@ -21,21 +21,31 @@ final class PropertyAccess /** * Creates a property accessor with the default configuration. * + * @param bool $throwExceptionOnInvalidIndex + * * @return PropertyAccessor The new property accessor */ - public static function createPropertyAccessor() + public static function createPropertyAccessor($throwExceptionOnInvalidIndex = false) { - return self::createPropertyAccessorBuilder()->getPropertyAccessor(); + return self::createPropertyAccessorBuilder($throwExceptionOnInvalidIndex)->getPropertyAccessor(); } /** * Creates a property accessor builder. * + * @param bool $enableExceptionOnInvalidIndex + * * @return PropertyAccessorBuilder The new property accessor builder */ - public static function createPropertyAccessorBuilder() + public static function createPropertyAccessorBuilder($enableExceptionOnInvalidIndex = false) { - return new PropertyAccessorBuilder(); + $propertyAccessorBuilder = new PropertyAccessorBuilder(); + + if ($enableExceptionOnInvalidIndex) { + $propertyAccessorBuilder->enableExceptionOnInvalidIndex(); + } + + return $propertyAccessorBuilder; } /** From 35131b9b5df5068d0b8a607f80c095e0aebe2b58 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 6 Jun 2016 21:21:05 +0200 Subject: [PATCH 2/5] Keep BC by using func_get_arg Document param (commented) Fabbot fixes --- .../PropertyAccess/PropertyAccess.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccess.php b/src/Symfony/Component/PropertyAccess/PropertyAccess.php index aad11d7a019a1..08b6345b3dbd3 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccess.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccess.php @@ -21,25 +21,36 @@ final class PropertyAccess /** * Creates a property accessor with the default configuration. * - * @param bool $throwExceptionOnInvalidIndex + * @param bool $throwExceptionOnInvalidIndex Will be added to the signature in 4.0 * * @return PropertyAccessor The new property accessor */ - public static function createPropertyAccessor($throwExceptionOnInvalidIndex = false) + public static function createPropertyAccessor(/* $throwExceptionOnInvalidIndex = false */) { + $throwExceptionOnInvalidIndex = false; + + if (func_num_args()) { + $throwExceptionOnInvalidIndex = func_get_arg(0); + } + return self::createPropertyAccessorBuilder($throwExceptionOnInvalidIndex)->getPropertyAccessor(); } /** * Creates a property accessor builder. * - * @param bool $enableExceptionOnInvalidIndex + * @param bool $enableExceptionOnInvalidIndex Will be added to the signature in 4.0. * * @return PropertyAccessorBuilder The new property accessor builder */ - public static function createPropertyAccessorBuilder($enableExceptionOnInvalidIndex = false) + public static function createPropertyAccessorBuilder(/* $enableExceptionOnInvalidIndex = false */) { $propertyAccessorBuilder = new PropertyAccessorBuilder(); + $enableExceptionOnInvalidIndex = false; + + if (func_num_args()) { + $enableExceptionOnInvalidIndex = func_get_arg(0); + } if ($enableExceptionOnInvalidIndex) { $propertyAccessorBuilder->enableExceptionOnInvalidIndex(); From 8eb11fcfd2acb4792434e4bdfc4ac3f9e4f1d7b8 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Mon, 6 Jun 2016 23:55:35 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=C2=A9Add=20test=20for=20PropertyAccess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tests/PropertyAccessTest.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php new file mode 100644 index 0000000000000..d2cf340fdff20 --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\PropertyAccess\Tests; + +use Symfony\Component\PropertyAccess\PropertyAccess; +use Symfony\Component\PropertyAccess\PropertyAccessor; + +/** + * @author Robin Chalas assertInstanceOf(PropertyAccessor::class, PropertyAccess::createPropertyAccessor()); + } + + public function testCreatePropertyAccessorWithExceptionOnInvalidIndex() + { + $this->assertInstanceOf(PropertyAccessor::class, PropertyAccess::createPropertyAccessor(true)); + } +} From fa8b71144d5f214dd3fa275d801bd727db02d2a0 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 7 Jun 2016 09:54:47 +0200 Subject: [PATCH 4/5] Remove hack --- .../PropertyAccess/PropertyAccess.php | 19 ++++--------------- .../Tests/PropertyAccessTest.php | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccess.php b/src/Symfony/Component/PropertyAccess/PropertyAccess.php index 08b6345b3dbd3..aad11d7a019a1 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccess.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccess.php @@ -21,36 +21,25 @@ final class PropertyAccess /** * Creates a property accessor with the default configuration. * - * @param bool $throwExceptionOnInvalidIndex Will be added to the signature in 4.0 + * @param bool $throwExceptionOnInvalidIndex * * @return PropertyAccessor The new property accessor */ - public static function createPropertyAccessor(/* $throwExceptionOnInvalidIndex = false */) + public static function createPropertyAccessor($throwExceptionOnInvalidIndex = false) { - $throwExceptionOnInvalidIndex = false; - - if (func_num_args()) { - $throwExceptionOnInvalidIndex = func_get_arg(0); - } - return self::createPropertyAccessorBuilder($throwExceptionOnInvalidIndex)->getPropertyAccessor(); } /** * Creates a property accessor builder. * - * @param bool $enableExceptionOnInvalidIndex Will be added to the signature in 4.0. + * @param bool $enableExceptionOnInvalidIndex * * @return PropertyAccessorBuilder The new property accessor builder */ - public static function createPropertyAccessorBuilder(/* $enableExceptionOnInvalidIndex = false */) + public static function createPropertyAccessorBuilder($enableExceptionOnInvalidIndex = false) { $propertyAccessorBuilder = new PropertyAccessorBuilder(); - $enableExceptionOnInvalidIndex = false; - - if (func_num_args()) { - $enableExceptionOnInvalidIndex = func_get_arg(0); - } if ($enableExceptionOnInvalidIndex) { $propertyAccessorBuilder->enableExceptionOnInvalidIndex(); diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php index d2cf340fdff20..9787ab37482a0 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php @@ -17,7 +17,7 @@ /** * @author Robin Chalas Date: Thu, 9 Jun 2016 13:11:30 +0200 Subject: [PATCH 5/5] Add the second $enableMagicCall missing argument --- .../Component/PropertyAccess/PropertyAccess.php | 10 +++++++--- .../PropertyAccess/Tests/PropertyAccessTest.php | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccess.php b/src/Symfony/Component/PropertyAccess/PropertyAccess.php index aad11d7a019a1..6f27408cab0c0 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccess.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccess.php @@ -25,9 +25,9 @@ final class PropertyAccess * * @return PropertyAccessor The new property accessor */ - public static function createPropertyAccessor($throwExceptionOnInvalidIndex = false) + public static function createPropertyAccessor($throwExceptionOnInvalidIndex = false, $magicCall = false) { - return self::createPropertyAccessorBuilder($throwExceptionOnInvalidIndex)->getPropertyAccessor(); + return self::createPropertyAccessorBuilder($throwExceptionOnInvalidIndex, $magicCall)->getPropertyAccessor(); } /** @@ -37,7 +37,7 @@ public static function createPropertyAccessor($throwExceptionOnInvalidIndex = fa * * @return PropertyAccessorBuilder The new property accessor builder */ - public static function createPropertyAccessorBuilder($enableExceptionOnInvalidIndex = false) + public static function createPropertyAccessorBuilder($enableExceptionOnInvalidIndex = false, $enableMagicCall = false) { $propertyAccessorBuilder = new PropertyAccessorBuilder(); @@ -45,6 +45,10 @@ public static function createPropertyAccessorBuilder($enableExceptionOnInvalidIn $propertyAccessorBuilder->enableExceptionOnInvalidIndex(); } + if ($enableMagicCall) { + $propertyAccessorBuilder->enableMagicCall(); + } + return $propertyAccessorBuilder; } diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php index 9787ab37482a0..a584dcb3bb736 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php @@ -28,4 +28,9 @@ public function testCreatePropertyAccessorWithExceptionOnInvalidIndex() { $this->assertInstanceOf(PropertyAccessor::class, PropertyAccess::createPropertyAccessor(true)); } + + public function testCreatePropertyAccessorWithMagicCallEnabled() + { + $this->assertInstanceOf(PropertyAccessor::class, PropertyAccess::createPropertyAccessor(false, true)); + } }