8000 [PropertyAccess] Added missing new args in `PropertyAccessorBuilder` by HeahDude · Pull Request #36119 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PropertyAccess] Added missing new args in PropertyAccessorBuilder #36119

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

Merged
Merged
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
44 changes: 43 additions & 1 deletion src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -157,13 +169,43 @@ public function getCacheItemPool()
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.
*
* @return PropertyAccessorInterface The built PropertyAccessor
*/
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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
{
Expand Down Expand Up @@ -63,4 +65,24 @@ public function testUseCache()
$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());
}
}
0