Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 849250a

Browse files
committed
Add context variable to be consistent with others extractor, use it for allowing constructor extraction in write mutator
1 parent 4f81ee7 commit 849250a

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function isInitializable(string $class, string $property, array $context
192192
/**
193193
* {@inheritdoc}
194194
*/
195-
public function getReadAccessor(string $class, string $property): ?ReadAccessor
195+
public function getReadAccessor(string $class, string $property, array $context = []): ?ReadAccessor
196196
{
197197
try {
198198
$reflClass = new \ReflectionClass($class);
@@ -243,14 +243,15 @@ public function getReadAccessor(string $class, string $property): ?ReadAccessor
243243
/**
244244
* {@inheritdoc}
245245
*/
246-
public function getWriteMutator(string $class, string $property, bool $allowConstruct = true): ?WriteMutator
246+
public function getWriteMutator(string $class, string $property, array $context = []): ?WriteMutator
247247
{
248248
try {
249249
$reflClass = new \ReflectionClass($class);
250250
} catch (\ReflectionException $e) {
251251
return null;
252252
}
253253

254+
$allowConstruct = $context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction;
254255
$hasProperty = $reflClass->hasProperty($property);
255256
$camelized = $this->camelize($property);
256257
$accessParameter = null;

src/Symfony/Component/PropertyInfo/ReadAccessorExtractorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
*/
1919
interface ReadAccessorExtractorInterface
2020
{
21-
public function getReadAccessor(string $class, string $property): ?ReadAccessor;
21+
public function getReadAccessor(string $class, string $property, array $context = []): ?ReadAccessor;
2222
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ public function readAccessorProvider(): array
382382
*/
383383
public function testGetWriteMutator($class, $property, $allowConstruct, $found, $type, $name, $addName, $removeName, $private, $static, $hasParameter)
384384
{
385-
$writeMutator = $this->extractor->getWriteMutator($class, $property, $allowConstruct);
385+
$writeMutator = $this->extractor->getWriteMutator($class, $property, [
386+
'enable_constructor_extraction' => $allowConstruct
387+
]);
386388

387389
if (!$found) {
388390
$this->assertNull($writeMutator);

src/Symfony/Component/PropertyInfo/WriteMutatorExtractorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@
1818
*/
1919
interface WriteMutatorExtractorInterface
2020
{
21-
public function getWriteMutator(string $class, string $property, bool $allowConstructor = true): ?WriteMutator;
21+
public function getWriteMutator(string $class, string $property, array $context = []): ?WriteMutator;
2222
}

0 commit comments

Comments
 (0)