[2.0][DDC-366] Fixed. Fully qualified names were borked in the lexer as well. Tests didnt catch it because of unfortunate namespace constellations. Fixed now.
This commit is contained in:
parent
b274a69ec2
commit
7badced187
@ -84,6 +84,17 @@ class AnnotationReader
|
||||
$this->_parser->setDefaultAnnotationNamespace($defaultNamespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an alias for an annotation namespace.
|
||||
*
|
||||
* @param $namespace
|
||||
* @param $alias
|
||||
*/
|
||||
public function setAnnotationNamespaceAlias($namespace, $alias)
|
||||
{
|
||||
$this->_parser->setAnnotationNamespaceAlias($namespace, $alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the annotations applied to a class.
|
||||
*
|
||||
|
@ -57,7 +57,7 @@ class Lexer extends \Doctrine\Common\Lexer
|
||||
protected function getCatchablePatterns()
|
||||
{
|
||||
return array(
|
||||
'[a-z_][a-z0-9_\\\]*',
|
||||
'[a-z_][a-z0-9_:]*',
|
||||
'(?:[0-9]+(?:[\.][0-9]+)*)(?:e[+-]?[0-9]+)?',
|
||||
'"(?:[^"]|"")*"'
|
||||
);
|
||||
|
@ -213,10 +213,12 @@ class Parser
|
||||
|
||||
/**
|
||||
* Annotation ::= "@" AnnotationName ["(" [Values] ")"]
|
||||
* AnnotationName ::= QualifiedName | SimpleName
|
||||
* AnnotationName ::= QualifiedName | SimpleName | AliasedName
|
||||
* QualifiedName ::= NameSpacePart "\" {NameSpacePart "\"}* SimpleName
|
||||
* AliasedName ::= Alias ":" SimpleName
|
||||
* NameSpacePart ::= identifier
|
||||
* SimpleName ::= identifier
|
||||
* Alias ::= identifier
|
||||
*
|
||||
* @return mixed False if it is not a valid Annotation; instance of Annotation subclass otherwise.
|
||||
*/
|
||||
@ -228,7 +230,7 @@ class Parser
|
||||
$this->match(Lexer::T_AT);
|
||||
$this->match(Lexer::T_IDENTIFIER);
|
||||
$nameParts[] = $this->_lexer->token['value'];
|
||||
|
||||
|
||||
while ($this->_lexer->isNextToken(Lexer::T_NAMESPACE_SEPARATOR)) {
|
||||
$this->match(Lexer::T_NAMESPACE_SEPARATOR);
|
||||
$this->match(Lexer::T_IDENTIFIER);
|
||||
@ -237,9 +239,12 @@ class Parser
|
||||
|
||||
// Effectively pick the name of class (append default NS if none, grab from NS alias, etc)
|
||||
if (count($nameParts) == 1) {
|
||||
$name = $this->_defaultAnnotationNamespace . $nameParts[0];
|
||||
} else if (count($nameParts) == 2 && isset($this->_namespaceAliases[$nameParts[0]])) {
|
||||
$name = $this->_namespaceAliases[$nameParts[0]] . $nameParts[1];
|
||||
if (strpos($nameParts[0], ':')) {
|
||||
list ($alias, $simpleName) = explode(':', $nameParts[0]);
|
||||
$name = $this->_namespaceAliases[$alias] . $simpleName;
|
||||
} else {
|
||||
$name = $this->_defaultAnnotationNamespace . $nameParts[0];
|
||||
}
|
||||
} else {
|
||||
$name = implode('\\', $nameParts);
|
||||
}
|
||||
|
@ -100,6 +100,29 @@ DOCBLOCK;
|
||||
$parser = $this->createTestParser();
|
||||
$parser->parse("@Name(foo='bar')");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group parse
|
||||
*/
|
||||
public function testAnnotationNamespaceAlias()
|
||||
{
|
||||
$parser = new Parser;
|
||||
$parser->setAnnotationNamespaceAlias('Doctrine\Tests\Common\Annotations\\', 'alias');
|
||||
$docblock = <<<DOCBLOCK
|
||||
/**
|
||||
* Some nifty class.
|
||||
*
|
||||
* @author Mr.X
|
||||
* @alias:Name(foo="stuff")
|
||||
*/
|
||||
DOCBLOCK;
|
||||
|
||||
$result = $parser->parse($docblock);
|
||||
$this->assertEquals(1, count($result));
|
||||
$annot = $result['Doctrine\Tests\Common\Annotations\Name'];
|
||||
$this->assertTrue($annot instanceof Name);
|
||||
$this->assertEquals("stuff", $annot->foo);
|
||||
}
|
||||
|
||||
public function createTestParser()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user