Skip to content

Commit

Permalink
Fixed usage of inject annotations in traits
Browse files Browse the repository at this point in the history
  • Loading branch information
enumag authored and dg committed Jan 6, 2015
1 parent 8d9fbae commit e2be0dd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/DI/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
49 changes: 49 additions & 0 deletions tests/DI/Helpers.getInjectProperties().traits.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* Test: Nette\DI\Helpers::getInjectProperties() with traits
* @phpversion 5.4
*/

namespace A
{
class AInjected
{

}
}

namespace B
{
use A\AInjected;

trait BTrait
{
/** @var AInjected @inject */
public $varA;
}
}

namespace C
{
class CClass
{
use \B\BTrait;
}
}

namespace
{
use Nette\DI\Helpers;
use Nette\Reflection\ClassType;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';


$refC = ClassType::from('C\CClass');

Assert::same( array(
'varA' => 'A\AInjected',
), Helpers::getInjectProperties($refC) );
}

0 comments on commit e2be0dd

Please sign in to comment.