8000 [PropertyAccess] Added missing new args in PropertyAccessorBuilder · symfony/symfony@e1be8cd · GitHub
[go: up one dir, main page]

Skip to content

Commit e1be8cd

Browse files
committed
[PropertyAccess] Added missing new args in PropertyAccessorBuilder
1 parent c0ee02b commit e1be8cd

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessorBuilder.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\PropertyAccess;
1313

1414
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
16+
use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
1517

1618
/**
1719
* A configurable builder to create a PropertyAccessor.
@@ -29,6 +31,16 @@ class PropertyAccessorBuilder
2931
*/
3032
private $cacheItemPool;
3133

34+
/**
35+
* @var PropertyReadInfoExtractorInterface|null
36+
*/
37+
private $readInfoExtractor;
38+
39+
/**
40+
* @var PropertyWriteInfoExtractorInterface|null
41+
*/
42+
private $writeInfoExtractor;
43+
3244
/**
3345
* Enables the use of "__call" by the PropertyAccessor.
3446
*
@@ -157,13 +169,43 @@ public function getCacheItemPool()
157169
return $this->cacheItemPool;
158170
}
159171

172+
/**
173+
* @return $this
174+
*/
175+
public function setReadInfoExtractor(?PropertyReadInfoExtractorInterface $readInfoExtractor)
176+
{
177+
$this->readInfoExtractor = $readInfoExtractor;
178+
179+
return $this;
180+
}
181+
182+
public function getReadInfoExtractor(): ?PropertyReadInfoExtractorInterface
183+
{
184+
return $this->readInfoExtractor;
185+
}
186+
187+
/**
188+
* @return $this
189+
*/
190+
public function setWriteInfoExtractor(?PropertyWriteInfoExtractorInterface $writeInfoExtractor)
191+
{
192+
$this->writeInfoExtractor = $writeInfoExtractor;
193+
194+
return $this;
195+
}
196+
197+
public function getWriteInfoExtractor(): ?PropertyWriteInfoExtractorInterface
198+
{
199+
return $this->writeInfoExtractor;
200+
}
201+
160202
/**
161203
* Builds and returns a new PropertyAccessor object.
162204
*
163205
* @return PropertyAccessorInterface The built PropertyAccessor
164206
*/
165207
public function getPropertyAccessor()
166208
{
167-
return new PropertyAccessor($this->magicCall, $this->throwExceptionOnInvalidIndex, $this->cacheItemPool, $this->throwExceptionOnInvalidPropertyPath);
209+
return new PropertyAccessor($this->magicCall, $this->throwExceptionOnInvalidIndex, $this->cacheItemPool, $this->throwExceptionOnInvalidPropertyPath, $this->readInfoExtractor, $this->writeInfoExtractor);
168210
}
169211
}

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorBuilderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1616
use Symfony\Component\PropertyAccess\PropertyAccessor;
1717
use Symfony\Component\PropertyAccess\PropertyAccessorBuilder;
18+
use Symfony\Component\PropertyInfo\PropertyReadInfoExtractorInterface;
19+
use Symfony\Component\PropertyInfo\PropertyWriteInfoExtractorInterface;
1820

1921
class PropertyAccessorBuilderTest extends TestCase
2022
{
@@ -63,4 +65,24 @@ public function testUseCache()
6365
$this->assertEquals($cacheItemPool, $this->builder->getCacheItemPool());
6466
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
6567
}
68+
69+
public function testUseReadInfoExtractor()
70+
{
71+
$readInfoExtractor = $this->createMock(PropertyReadInfoExtractorInterface::class);
72+
73+
$this->builder->setReadInfoExtractor($readInfoExtractor);
74+
75+
$this->assertSame($readInfoExtractor, $this->builder->getReadInfoExtractor());
76+
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
77+
}
78+
79+
public function testUseWriteInfoExtractor()
80+
{
81+
$writeInfoExtractor = $this->createMock(PropertyWriteInfoExtractorInterface::class);
82+
83+
$this->builder->setWriteInfoExtractor($writeInfoExtractor);
84+
85+
$this->assertSame($writeInfoExtractor, $this->builder->getWriteInfoExtractor());
86+
$this->assertInstanceOf(PropertyAccessor::class, $this->builder->getPropertyAccessor());
87+
}
6688
}

0 commit comments

Comments
 (0)
0