Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Reverted annotation autoloading functionality, reintroducing a config…

…uration switch, defaulting to false. Too much trouble in paradise otherwise.
  • Loading branch information...
commit 30eac01b12afc318bc142b79a339ce0b9fb81239 1 parent f34d581
@romanb romanb authored
View
25 lib/Doctrine/Common/Annotations/AnnotationReader.php
@@ -101,6 +101,31 @@ public function setAnnotationNamespaceAlias($namespace, $alias)
}
/**
+ * Sets a flag whether to try to autoload annotation classes, as well as to distinguish
+ * between what is an annotation and what not by triggering autoloading.
+ *
+ * NOTE: Autoloading of annotation classes is inefficient and requires silently failing
+ * autoloaders. In particular, setting this option to TRUE renders this AnnotationReader
+ * incompatible with a {@link ClassLoader}.
+ * @param boolean $bool Boolean flag.
+ */
+ public function setAutoloadAnnotations($bool)
+ {
+ $this->parser->setAutoloadAnnotations($bool);
+ }
+
+ /**
+ * Gets a flag whether to try to autoload annotation classes.
+ *
+ * @see setAutoloadAnnotations
+ * @return boolean
+ */
+ public function getAutoloadAnnotations()
+ {
+ return $this->parser->getAutoloadAnnotations();
+ }
+
+ /**
* Gets the annotations applied to a class.
*
* @param string|ReflectionClass $class The name or ReflectionClass of the class from which
View
34 lib/Doctrine/Common/Annotations/Parser.php
@@ -76,6 +76,11 @@ class Parser
private $context = '';
/**
+ * @var boolean Whether to try to autoload annotations that are not yet defined.
+ */
+ private $autoloadAnnotations = false;
+
+ /**
* Constructs a new AnnotationParser.
*/
public function __construct()
@@ -84,6 +89,31 @@ public function __construct()
}
/**
+ * Sets a flag whether to try to autoload annotation classes, as well as to distinguish
+ * between what is an annotation and what not by triggering autoloading.
+ *
+ * NOTE: Autoloading of annotation classes is inefficient and requires silently failing
+ * autoloaders. In particular, setting this option to TRUE renders the Parser
+ * incompatible with a {@link ClassLoader}.
+ * @param boolean $bool Boolean flag.
+ */
+ public function setAutoloadAnnotations($bool)
+ {
+ $this->autoloadAnnotations = $bool;
+ }
+
+ /**
+ * Gets a flag whether to try to autoload annotation classes.
+ *
+ * @see setAutoloadAnnotations
+ * @return boolean
+ */
+ public function getAutoloadAnnotations()
+ {
+ return $this->autoloadAnnotations;
+ }
+
+ /**
* Sets the default namespace that is assumed for an annotation that does not
* define a namespace prefix.
*
@@ -244,10 +274,10 @@ public function Annotation()
}
// Is it really an annotation?
- // If the lookahead is "(" it surely is, otherwise classExists decides.
+ // If the lookahead is "(" it surely is, otherwise class_exists decides.
if (
($this->lexer->lookahead == null || ! $this->lexer->isNextToken(Lexer::T_OPEN_PARENTHESIS)) &&
- ! ClassLoader::classExists($name)
+ ! class_exists($name, $this->autoloadAnnotations)
) {
$this->lexer->skipUntil(Lexer::T_AT);
return false;
View
6 tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php
@@ -12,6 +12,12 @@ public function testAnnotations()
{
$reader = new AnnotationReader(new \Doctrine\Common\Cache\ArrayCache);
$reader->setDefaultAnnotationNamespace('Doctrine\Tests\Common\Annotations\\');
+
+ $this->assertFalse($reader->getAutoloadAnnotations());
+ $reader->setAutoloadAnnotations(true);
+ $this->assertTrue($reader->getAutoloadAnnotations());
+ $reader->setAutoloadAnnotations(false);
+ $this->assertFalse($reader->getAutoloadAnnotations());
$class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\DummyClass');
$classAnnots = $reader->getClassAnnotations($class);
View
6 tests/Doctrine/Tests/Common/Annotations/ParserTest.php
@@ -12,6 +12,8 @@ public function testBasicAnnotations()
{
$parser = $this->createTestParser();
+ $this->assertFalse($parser->getAutoloadAnnotations());
+
// Marker annotation
$result = $parser->parse("@Name");
$annot = $result['Doctrine\Tests\Common\Annotations\Name'];
@@ -77,7 +79,9 @@ public function testNamespacedAnnotations()
/**
* Some nifty class.
*
- * @author Mr.X
+ * @package foo
+ * @subpackage bar
+ * @author Mr.X <mr@x.com>
* @Doctrine\Tests\Common\Annotations\Name(foo="bar")
* @ignore
*/
Please sign in to comment.
Something went wrong with that request. Please try again.