From 04854348555b344f95c9681dc378fb5e2a8fe6c9 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Wed, 23 Jan 2019 14:53:12 +0900 Subject: [PATCH] Update AnnotationReader's metadata parser to use list of known ignored annotation A parser used to collect parsing metadata basically ignores a known list of globally ignored annotation names, goes through loops checking annotations that do not need any checking. Let's fix that by communicating the list during initialization. --- lib/Doctrine/Annotations/AnnotationReader.php | 1 + .../Tests/Annotations/AbstractReaderTest.php | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/Doctrine/Annotations/AnnotationReader.php b/lib/Doctrine/Annotations/AnnotationReader.php index 1f2a2db68..51397dd3a 100644 --- a/lib/Doctrine/Annotations/AnnotationReader.php +++ b/lib/Doctrine/Annotations/AnnotationReader.php @@ -181,6 +181,7 @@ public function __construct(DocParser $parser = null) $this->preParser->setImports(self::$globalImports); $this->preParser->setIgnoreNotImportedAnnotations(true); + $this->preParser->setIgnoredAnnotationNames(self::$globalIgnoredNames); $this->phpParser = new PhpParser; } diff --git a/tests/Doctrine/Tests/Annotations/AbstractReaderTest.php b/tests/Doctrine/Tests/Annotations/AbstractReaderTest.php index a52fe21e9..b218db081 100644 --- a/tests/Doctrine/Tests/Annotations/AbstractReaderTest.php +++ b/tests/Doctrine/Tests/Annotations/AbstractReaderTest.php @@ -408,6 +408,28 @@ public function testInvalidAnnotationButIgnored() self::assertEmpty($reader->getPropertyAnnotations($class->getProperty('foo'))); } + public function testGloballyIgnoredAnnotationNotIgnored() : void + { + $reader = $this->getReader(); + $class = new \ReflectionClass(Fixtures\ClassDDC1660::class); + + $testLoader = static function (string $className) : bool { + if ($className === 'since') { + throw new \InvalidArgumentException('Globally ignored annotation names should never be passed to an autoloader.'); + } + + return false; + }; + + spl_autoload_register($testLoader, true, true); + + try { + self::assertEmpty($reader->getClassAnnotations($class)); + } finally { + spl_autoload_unregister($testLoader); + } + } + public function testAnnotationEnumeratorException() { $reader = $this->getReader();