From e2be0ddbddfbe427e65883fe18ca063964d58da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Tue, 6 Jan 2015 21:36:35 +0100 Subject: [PATCH] Fixed usage of inject annotations in traits --- composer.json | 2 +- src/DI/Helpers.php | 2 +- .../Helpers.getInjectProperties().traits.phpt | 49 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/DI/Helpers.getInjectProperties().traits.phpt diff --git a/composer.json b/composer.json index 106ee29d8..987b95bd9 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": ">=5.3.1", "nette/neon": "~2.3", - "nette/reflection": "~2.2", + "nette/reflection": "~2.3", "nette/php-generator": "~2.2", "nette/utils": "~2.3" }, diff --git a/src/DI/Helpers.php b/src/DI/Helpers.php index ba8303f70..2c5c5a094 100644 --- a/src/DI/Helpers.php +++ b/src/DI/Helpers.php @@ -156,7 +156,7 @@ public static function getInjectProperties(Nette\Reflection\ClassType $class, $c throw new Nette\InvalidStateException("Property $property has no @var annotation."); } - $type = Nette\Reflection\AnnotationsParser::expandClassName($type, $property->getDeclaringClass()); + $type = Nette\Reflection\AnnotationsParser::expandClassName($type, Nette\Reflection\Helpers::getDeclaringClass($property)); if (!class_exists($type) && !interface_exists($type)) { throw new Nette\InvalidStateException("Class or interface '$type' used in @var annotation at $property not found. Check annotation and 'use' statements."); } elseif ($container && !$container->getByType($type, FALSE)) { diff --git a/tests/DI/Helpers.getInjectProperties().traits.phpt b/tests/DI/Helpers.getInjectProperties().traits.phpt new file mode 100644 index 000000000..4d519937e --- /dev/null +++ b/tests/DI/Helpers.getInjectProperties().traits.phpt @@ -0,0 +1,49 @@ + 'A\AInjected', + ), Helpers::getInjectProperties($refC) ); +}