Skip to content

Commit 21deed7

Browse files
enumagdg
authored andcommitted
Fixed usage of inject annotations in traits [Closes #33]
1 parent 8d9fbae commit 21deed7

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"require": {
1717
"php": ">=5.3.1",
1818
"nette/neon": "~2.3",
19-
"nette/reflection": "~2.2",
19+
"nette/reflection": "~2.3",
2020
"nette/php-generator": "~2.2",
2121
"nette/utils": "~2.3"
2222
},

src/DI/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static function getInjectProperties(Nette\Reflection\ClassType $class, $c
156156
throw new Nette\InvalidStateException("Property $property has no @var annotation.");
157157
}
158158

159-
$type = Nette\Reflection\AnnotationsParser::expandClassName($type, $property->getDeclaringClass());
159+
$type = Nette\Reflection\AnnotationsParser::expandClassName($type, Nette\Reflection\Helpers::getDeclaringClass($property));
160160
if (!class_exists($type) && !interface_exists($type)) {
161161
throw new Nette\InvalidStateException("Class or interface '$type' used in @var annotation at $property not found. Check annotation and 'use' statements.");
162162
} elseif ($container && !$container->getByType($type, FALSE)) {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\DI\Helpers::getInjectProperties() with traits
5+
* @phpversion 5.4
6+
*/
7+
8+
namespace A
9+
{
10+
class AInjected
11+
{
12+
13+
}
14+
}
15+
16+
namespace B
17+
{
18+
use A\AInjected;
19+
20+
trait BTrait
21+
{
22+
/** @var AInjected @inject */
23+
public $varA;
24+
}
25+
}
26+
27+
namespace C
28+
{
29+
class CClass
30+
{
31+
use \B\BTrait;
32+
}
33+
}
34+
35+
namespace
36+
{
37+
use Nette\DI\Helpers;
38+
use Nette\Reflection\ClassType;
39+
use Tester\Assert;
40+
41+
require __DIR__ . '/../bootstrap.php';
42+
43+
44+
$refC = ClassType::from('C\CClass');
45+
46+
Assert::same( array(
47+
'varA' => 'A\AInjected',
48+
), Helpers::getInjectProperties($refC) );
49+
}

0 commit comments

Comments
 (0)