8000 [PropertyAccess] Add missing arguments to PropertyAccess::createPropertyAccessor() by chalasr · Pull Request #18977 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/Symfony/Component/PropertyAccess/PropertyAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to de 8000 scribe this comment to others. Learn more.

I don't agree with this change. A builder is exactly there to dynamically set the behavior and not have a huge list of arguments. If there are new flags for the property accessor, you don't want to add every new field as argument for the builder. Then there is no point of a builder.

{
return new PropertyAccessorBuilder();
$propertyAccessorBuilder = new PropertyAccessorBuilder();

if ($enableExceptionOnInvalidIndex) {
$propertyAccessorBuilder->enableExceptionOnInvalidIndex();
}

if ($enableMagicCall) {
$propertyAccessorBuilder->enableMagicCall();
}

return $propertyAccessorBuilder;
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/Symfony/Component/PropertyAccess/Tests/PropertyAccessTest.php
Original file line number Diff line number Diff line change
@@ -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));
}
}
0