diff --git a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php index 5a3ae61..283c9f6 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -27,13 +27,6 @@ class AnnotatedClassDiscovery implements DiscoveryInterface { protected $pluginNamespaces; /** - * The namespaces of classes that can be used as annotations. - * - * @var array - */ - protected $annotationNamespaces; - - /** * The name of the annotation that contains the plugin definition. * * The class corresponding to this name must implement @@ -77,11 +70,7 @@ public function getDefinitions() { $reader->addGlobalIgnoredName('file'); // Register the namespaces of classes that can be used for annotations. - AnnotationRegistry::registerLoader( - function ($className) { - return class_exists($className); - } - ); + AnnotationRegistry::registerLoader(array($this, 'loadAnnotationClass')); // Search for classes within all PSR-0 namespace locations. foreach ($this->getPluginNamespaces() as $namespace => $dirs) { @@ -111,10 +100,25 @@ function ($className) { } } } + + // Don't let annotation loaders pile up. + AnnotationRegistry::reset(); + return $definitions; } /** + * Annotation loader callback + * + * @param string $class + * @return bool + * TRUE, if $class should be accepted as an annotation class. + */ + public function loadAnnotationClass($class) { + return class_exists($class); + } + + /** * Returns an array of PSR-0 namespaces to search for plugin classes. */ protected function getPluginNamespaces() { diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index e033caf..d6b5378 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -69,6 +69,21 @@ public function getDefinitions() { } /** + * Annotation loader callback + * + * @param string $class + * @return bool + * TRUE, if $class should be accepted as an annotation class. + */ + public function loadAnnotationClass($class) { + return 1 + && 0 === strpos($class, 'Drupal\\') + && FALSE !== strpos($class, '\Annotation\\') + && class_exists($class) + ; + } + + /** * Extracts the provider name from a Drupal namespace. * * @param string $namespace diff --git a/core/modules/views/lib/Drupal/views/Plugin/Discovery/ViewsHandlerDiscovery.php b/core/modules/views/lib/Drupal/views/Plugin/Discovery/ViewsHandlerDiscovery.php index 460ef5a..a3a08c0 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Discovery/ViewsHandlerDiscovery.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Discovery/ViewsHandlerDiscovery.php @@ -41,16 +41,12 @@ function __construct($type, \Traversable $root_namespaces) { $this->type = $type; $this->rootNamespacesIterator = $root_namespaces; - $annotation_namespaces = array( - 'Drupal\Component\Annotation' => DRUPAL_ROOT . '/core/lib', - ); $plugin_namespaces = array(); foreach ($root_namespaces as $namespace => $dir) { $plugin_namespaces["$namespace\\Plugin\\views\\{$type}"] = array($dir); } $this->pluginNamespaces = $plugin_namespaces; - $this->annotationNamespaces = $annotation_namespaces; $this->pluginDefinitionAnnotationName = 'Drupal\Component\Annotation\PluginID'; }