diff --git a/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php b/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php index 94aa4ecc35..41853abbfe 100644 --- a/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php +++ b/src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php @@ -12,6 +12,8 @@ namespace Symfony\Component\PropertyAccess; use Psr\Cache\CacheItemPoolInterface; +use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface; +use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface; /** * A configurable builder to create a PropertyAccessor. @@ -29,6 +31,16 @@ class PropertyAccessorBuilder */ private $cacheItemPool; + /** + * @var PropertyReadInfoExtractorInterface|null + */ + private $readInfoExtractor; + + /** + * @var PropertyWriteInfoExtractorInterface|null + */ + private $writeInfoExtractor; + /** * Enables the use of "__call" by the PropertyAccessor. * @@ -157,6 +169,36 @@ class PropertyAccessorBuilder return $this->cacheItemPool; } + /** + * @return $this + */ + public function setReadInfoExtractor(?PropertyReadInfoExtractorInterface $readInfoExtractor) + { + $this->readInfoExtractor = $readInfoExtractor; + + return $this; + } + + public function getReadInfoExtractor(): ?PropertyReadInfoExtractorInterface + { + return $this->readInfoExtractor; + } + + /** + * @return $this + */ + public function setWriteInfoExtractor(?PropertyWriteInfoExtractorInterface $writeInfoExtractor) + { + $this->writeInfoExtractor = $writeInfoExtractor; + + return $this; + } + + public function getWriteInfoExtractor(): ?PropertyWriteInfoExtractorInterface + { + return $this->writeInfoExtractor; + } + /** * Builds and returns a new PropertyAccessor object. * @@ -164,6 +206,6 @@ class PropertyAccessorBuilder */ public function getPropertyAccessor() { - return new PropertyAccessor($this->magicCall, $this->throwExceptionOnInvalidIndex, $this->cacheItemPool, $this->throwExceptionOnInvalidPropertyPath); + return new PropertyAccessor($this->magicCall, $this->throwExceptionOnInvalidIndex, $this->cacheItemPool, $this->throwExceptionOnInvalidPropertyPath, $this->readInfoExtractor, $this->writeInfoExtractor); } } diff --git a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorBuilderTest.php b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorBuilderTest.php index d35ffccc4a..eb46d300da 100644 --- a/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorBuilderTest.php +++ b/src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorBuilderTest.php @@ -15,6 +15,8 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\PropertyAccess\PropertyAccessor; use Symfony\Component\PropertyAccess\PropertyAccessorBuilder; +use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface; +use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface; class PropertyAccessorBuilderTest extends TestCase { @@ -63,4 +65,24 @@ class PropertyAccessorBuilderTest extends TestCase $this->assertEquals($cacheItemPool, $this->builder->getCacheItemPool()); $this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor()); } + + public function testUseReadInfoExtractor() + { + $readInfoExtractor = $this->createMock(PropertyReadInfoExtractorInterface::class); + + $this->builder->setReadInfoExtractor($readInfoExtractor); + + $this->assertSame($readInfoExtractor, $this->builder->getReadInfoExtractor()); + $this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor()); + } + + public function testUseWriteInfoExtractor() + { + $writeInfoExtractor = $this->createMock(PropertyWriteInfoExtractorInterface::class); + + $this->builder->setWriteInfoExtractor($writeInfoExtractor); + + $this->assertSame($writeInfoExtractor, $this->builder->getWriteInfoExtractor()); + $this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor()); + } }