Permalink
Browse files

[DCOM-44] Throw exception if namespaced annotation does not exist.

  • Loading branch information...
beberlei committed Apr 5, 2011
1 parent 440e050 commit 8967f476ddcdb7b9017a8be7f774979ca4c72247
@@ -313,6 +313,7 @@ public function Annotation()
}
// Effectively pick the name of the class (append default NS if none, grab from NS alias, etc)
+ $namespacedAnnotation = false;
if (strpos($nameParts[0], ':')) {
list ($alias, $nameParts[0]) = explode(':', $nameParts[0]);
@@ -323,6 +324,7 @@ public function Annotation()
}
$name = $this->namespaceAliases[$alias] . implode('\\', $nameParts);
+ $namespacedAnnotation = true;
} else if (count($nameParts) == 1) {
$name = $this->defaultAnnotationNamespace . $nameParts[0];
} else {
@@ -331,6 +333,10 @@ public function Annotation()
// Does the annotation class exist?
if ( ! class_exists($name, $this->autoloadAnnotations)) {
+ if ($namespacedAnnotation) {

This comment has been minimized.

Show comment Hide comment
@l3pp4rd

l3pp4rd Apr 6, 2011

Since class_exists throws fatal error if class is not loaded and does not exists, when using Doctrine\Common\ClassLoader is used, that makes it impossible to read specific annotations without preloading all at once.
Another issue is that it is now impossible to have same alias for different namespaces, in case if you want to read a part of annotations

@l3pp4rd

l3pp4rd Apr 6, 2011

Since class_exists throws fatal error if class is not loaded and does not exists, when using Doctrine\Common\ClassLoader is used, that makes it impossible to read specific annotations without preloading all at once.
Another issue is that it is now impossible to have same alias for different namespaces, in case if you want to read a part of annotations

This comment has been minimized.

Show comment Hide comment
@l3pp4rd

l3pp4rd Apr 7, 2011

So indeed this breaks possibility to use different namespaces for single alias, I had to make same namespace, but maybe that is how it had to be from the start.
Usage of ClassLoader::classExists($class) seems ugly since class_exists triggers fatal while it should return false. I understand that it is a performance gain, but it may complicate usage of it.

@l3pp4rd

l3pp4rd Apr 7, 2011

So indeed this breaks possibility to use different namespaces for single alias, I had to make same namespace, but maybe that is how it had to be from the start.
Usage of ClassLoader::classExists($class) seems ugly since class_exists triggers fatal while it should return false. I understand that it is a performance gain, but it may complicate usage of it.

This comment has been minimized.

Show comment Hide comment
@schmittjoh

schmittjoh Apr 7, 2011

Member
@schmittjoh

schmittjoh via email Apr 7, 2011

Member

This comment has been minimized.

Show comment Hide comment
@l3pp4rd

l3pp4rd Apr 7, 2011

another issue related to class loading:

http://www.doctrine-project.org/jira/browse/DCOM-47

+ throw AnnotationException::semanticalError('Annotation class "' . $name . '" does not exist.');
+ }
+
$this->lexer->skipUntil(Lexer::T_AT);
return false;
}
@@ -329,6 +329,21 @@ public function testNonexistantNamespaceAlias()
$this->assertEquals(0, count($result));
}
+
+ /**
+ * @group DCOM-44
+ */
+ public function testNonexistantAliasedAnnotation()
+ {
+ $parser = new Parser;
+ $parser->setAnnotationNamespaceAlias('Doctrine\Tests\Common\Annotations\\', 'common');
+
+ $this->setExpectedException(
+ "Doctrine\Common\Annotations\AnnotationException",
+ "[Semantical Error] Annotation class \"Doctrine\Tests\Common\Annotations\Foo\" does not exist."
+ );
+ $result = $parser->parse('@common:Foo');
+ }
}
class Name extends \Doctrine\Common\Annotations\Annotation {

1 comment on commit 8967f47

@schmittjoh

This comment has been minimized.

Show comment Hide comment
@schmittjoh

schmittjoh Apr 5, 2011

Member

Is this configurable?

Member

schmittjoh commented on 8967f47 Apr 5, 2011

Is this configurable?

Please sign in to comment.