[PropertyAccess] Added missing new args in PropertyAccessorBuilder

This commit is contained in:
Jules Pietri 2020-03-17 22:56:56 +01:00
parent c0ee02bf19
commit e1be8cd61b
No known key found for this signature in database
GPG Key ID: C924CC98D39AA885
2 changed files with 65 additions and 1 deletions

View File

@ -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);
}
}

View File

@ -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());
}
}