Skip to content

Commit 356fbf4

Browse files
authored
Fix the bug that value of Inject not work (#5065)
1 parent 6d4e45f commit 356fbf4

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Annotation/Inject.php

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ public function __construct(public ?string $value = null, public bool $required
2727
public function collectProperty(string $className, ?string $target): void
2828
{
2929
try {
30-
$reflectionClass = ReflectionManager::reflectClass($className);
30+
if (is_null($this->value)) {
31+
$reflectionClass = ReflectionManager::reflectClass($className);
3132

32-
$reflectionProperty = $reflectionClass->getProperty($target);
33+
$reflectionProperty = $reflectionClass->getProperty($target);
3334

34-
if (method_exists($reflectionProperty, 'hasType') && $reflectionProperty->hasType()) {
35-
/* @phpstan-ignore-next-line */
36-
$this->value = $reflectionProperty->getType()->getName();
37-
} else {
38-
$this->value = PhpDocReaderManager::getInstance()->getPropertyClass($reflectionProperty);
35+
if (method_exists($reflectionProperty, 'hasType') && $reflectionProperty->hasType()) {
36+
/* @phpstan-ignore-next-line */
37+
$this->value = $reflectionProperty->getType()->getName();
38+
} else {
39+
$this->value = PhpDocReaderManager::getInstance()->getPropertyClass($reflectionProperty);
40+
}
3941
}
4042

4143
if (empty($this->value)) {

0 commit comments

Comments
 (0)