diff --git a/src/Barryvdh/Reflection/DocBlock/Context.php b/src/Barryvdh/Reflection/DocBlock/Context.php index bbc97b4..63fce73 100644 --- a/src/Barryvdh/Reflection/DocBlock/Context.php +++ b/src/Barryvdh/Reflection/DocBlock/Context.php @@ -29,7 +29,10 @@ class Context /** @var string Name of the structural element, within the namespace. */ protected $lsen = ''; - + + /** @var string[] List of generics */ + protected $generics = array(); + /** * Cteates a new context. * @param string $namespace The namespace where this DocBlock @@ -42,13 +45,15 @@ class Context public function __construct( $namespace = '', array $namespace_aliases = array(), - $lsen = '' + $lsen = '', + array $generics = array() ) { if (!empty($namespace)) { $this->setNamespace($namespace); } $this->setNamespaceAliases($namespace_aliases); $this->setLSEN($lsen); + $this->setGenerics($generics); } /** @@ -76,6 +81,16 @@ class Context { return $this->lsen; } + + /** + * Returns the list of generics. + * + * @return string[] List of generics + */ + public function getGenerics() + { + return $this->generics; + } /** * Sets a new namespace. @@ -151,4 +166,17 @@ class Context $this->lsen = (string)$lsen; return $this; } + + /** + * Sets a new list of generics. + * + * @param string[] $generics The new list of generics. + * + * @return $this + */ + public function setGenerics(array $generics) + { + $this->generics = $generics; + return $this; + } } diff --git a/src/Barryvdh/Reflection/DocBlock/Type/Collection.php b/src/Barryvdh/Reflection/DocBlock/Type/Collection.php index a053901..585ccde 100644 --- a/src/Barryvdh/Reflection/DocBlock/Type/Collection.php +++ b/src/Barryvdh/Reflection/DocBlock/Type/Collection.php @@ -78,7 +78,7 @@ class Collection extends \ArrayObject array $generics = array() ) { $this->context = null === $context ? new Context() : $context; - $this->generics = $generics; + $this->generics = array_merge($this->context->getGenerics(), $generics); foreach ($types as $type) { $this->add($type); diff --git a/tests/Barryvdh/Reflection/DocBlock/Type/CollectionTest.php b/tests/Barryvdh/Reflection/DocBlock/Type/CollectionTest.php index 94c8548..9664ec3 100644 --- a/tests/Barryvdh/Reflection/DocBlock/Type/CollectionTest.php +++ b/tests/Barryvdh/Reflection/DocBlock/Type/CollectionTest.php @@ -157,7 +157,7 @@ class CollectionTest extends TestCase { $collection = new Collection( array(), - new Context('\My\Space', array('Alias' => '\My\Space\Aliasing')), + new Context('\My\Space', array('Alias' => '\My\Space\Aliasing'), '', array('TParent')), array('TValue') ); $collection->add($fixture); @@ -344,6 +344,7 @@ class CollectionTest extends TestCase array('TValue', array('TValue')), array('TValue[]', array('TValue[]')), array('TValue|DocBlock', array('TValue', $namespace . 'DocBlock')), + array('TParent', array('TParent')), ); } }