diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccess.php b/src/Symfony/Component/PropertyAccess/PropertyAccess.php index 6c9bb423d0..6f27408cab 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccess.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccess.php @@ -21,21 +21,35 @@ 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, $magicCall = false) { - return self::createPropertyAccessorBuilder()->getPropertyAccessor(); + return self::createPropertyAccessorBuilder($throwExceptionOnInvalidIndex, $magicCall)->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, $enableMagicCall = false) { - return new PropertyAccessorBuilder(); + $propertyAccessorBuilder = new PropertyAccessorBuilder(); + + if ($enableExceptionOnInvalidIndex) { + $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 new file mode 100644 index 0000000000..a584dcb3bb --- /dev/null +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php @@ -0,0 +1,36 @@ + + * + * 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)); + } + + public function testCreatePropertyAccessorWithMagicCallEnabled() + { + $this->assertInstanceOf(PropertyAccessor::class, PropertyAccess::createPropertyAccessor(false, true)); + } +}