[PropertyAccess] Add missing arguments to PropertyAccess::createPropertyAccessor()

This commit is contained in:
Robin Chalas 2016-06-06 13:19:45 +02:00 committed by Fabien Potencier
parent 052c314bd0
commit 5ded8047ec
2 changed files with 54 additions and 4 deletions

View File

@ -21,21 +21,35 @@ final class PropertyAccess
/** /**
* Creates a property accessor with the default configuration. * Creates a property accessor with the default configuration.
* *
* @param bool $throwExceptionOnInvalidIndex
*
* @return PropertyAccessor The new property accessor * @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. * Creates a property accessor builder.
* *
* @param bool $enableExceptionOnInvalidIndex
*
* @return PropertyAccessorBuilder The new property accessor builder * @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;
} }
/** /**

View File

@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <robin.chalas@gmail.com
*/
final class PropertyAccessTest extends \PHPUnit_Framework_TestCase
{
public function testCreatePropertyAccessor()
{
$this->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));
}
}