diff -u b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php --- b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -18,6 +18,9 @@ use DiscoveryTrait; + /** + * Whether the parser should return only wants class annotations. + */ const CLASSANNOTATIONOPTIMIZE = TRUE; /** @@ -114,7 +117,6 @@ AnnotationRegistry::reset(); // Register the namespaces of classes that can be used for annotations. AnnotationRegistry::registerLoader('class_exists'); - $generic_finder = $this->getFinder(); // Search for classes within all PSR-0 namespace locations. foreach ($this->getPluginNamespaces() as $namespace => $dirs) { @@ -140,7 +142,7 @@ // The filename is already known, so there is no need to find the // file. However, StaticReflectionParser needs a finder, so use a // mock version. - $finder = $generic_finder ?: MockFileFinder::create($fileinfo->getPathName()); + $finder = MockFileFinder::create($fileinfo->getPathName()); $parser = new StaticReflectionParser($class, $finder, static::CLASSANNOTATIONOPTIMIZE); /** @var $annotation \Drupal\Component\Annotation\AnnotationInterface */ @@ -194,9 +196,2 @@ - /** - * Returns a finder class for every prefix. - */ - protected function getFinder() { - // This class uses a finder per class. - } - } diff -u b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php --- b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -278,7 +278,7 @@ $this->processDefinition($definition, $plugin_id); } $this->alterDefinitions($definitions); - return ProviderFilterDecorator::filterDefinitions($definitions, [$this, 'providerExists']); + return ProviderFilterDecorator::filterDefinitions($definitions, function ($provider) { return $this->providerExists($provider); }); } /** @@ -299,7 +299,7 @@ * @return bool * TRUE if provider exists, FALSE otherwise. */ - public function providerExists($provider) { + protected function providerExists($provider) { return $this->moduleHandler->moduleExists($provider); } diff -u b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php --- b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -87,7 +87,7 @@ parent::prepareAnnotationDefinition($annotation, $class, $parser); if (!$annotation->getProvider()) { - $annotation->setProvider(static::getProviderFromNamespace($class)); + $annotation->setProvider($this->getProviderFromNamespace($class)); } } @@ -97,10 +97,10 @@ * @param string $namespace * The namespace to extract the provider from. * - * @return null|string + * @return string|null * The matching provider name, or NULL otherwise. */ - static public function getProviderFromNamespace($namespace) { + protected function getProviderFromNamespace($namespace) { preg_match('|^Drupal\\\\(?[\w]+)\\\\|', $namespace, $matches); if (isset($matches['provider'])) { diff -u b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscoveryAutomatedProviders.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscoveryAutomatedProviders.php --- b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscoveryAutomatedProviders.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscoveryAutomatedProviders.php @@ -2,7 +2,7 @@ namespace Drupal\Core\Plugin\Discovery; -use Doctrine\Common\Reflection\StaticReflectionParser; +use Doctrine\Common\Reflection\StaticReflectionParser as BaseStaticReflectionParser; use Drupal\Component\Annotation\AnnotationInterface; /** @@ -12,27 +12,20 @@ + /** + * {@inheritdoc} + */ const CLASSANNOTATIONOPTIMIZE = FALSE; /** * {@inheritdoc} */ - protected function prepareAnnotationDefinition(AnnotationInterface $annotation, $class, StaticReflectionParser $parser) { + protected function prepareAnnotationDefinition(AnnotationInterface $annotation, $class, BaseStaticReflectionParser $parser) { parent::prepareAnnotationDefinition($annotation, $class, $parser); - $m = (new \ReflectionClass(StaticReflectionParser::class))->getMethod('getParentStaticReflectionParser'); - $m->setAccessible(TRUE); + $finder = \Drupal::service('class_loader'); $providers = array_flip((array) $annotation->getProvider()); do { - foreach ($parser->getUseStatements() as $class) { - if ($provider = AnnotatedClassDiscovery::getProviderFromNamespace($class)) { - $providers[strtolower($provider)] = TRUE; - } - } - $parser = $m->invoke($parser); - } while ($parser->getClassName()); + $providers += array_flip(array_filter(array_map([$this, 'getProviderFromNamespace'], $parser->getUseStatements()))); + } while ($parser = StaticReflectionParser::getParentParser($parser, $finder)); $annotation->setProvider(array_keys($providers)); } - protected function getFinder() { - return \Drupal::service("Class_loader"); - } - } diff -u b/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php --- b/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/ProviderFilterDecorator.php @@ -84,3 +84,2 @@ - } reverted: --- b/core/modules/breakpoint/src/BreakpointManager.php +++ a/core/modules/breakpoint/src/BreakpointManager.php @@ -140,7 +140,7 @@ /** * {@inheritdoc} */ + protected function providerExists($provider) { - public function providerExists($provider) { return $this->moduleHandler->moduleExists($provider) || $this->themeHandler->themeExists($provider); } diff -u b/core/modules/migrate/src/Plugin/MigrateSourcePluginManager.php b/core/modules/migrate/src/Plugin/MigrateSourcePluginManager.php --- b/core/modules/migrate/src/Plugin/MigrateSourcePluginManager.php +++ b/core/modules/migrate/src/Plugin/MigrateSourcePluginManager.php @@ -5,8 +5,21 @@ use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscoveryAutomatedProviders; use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; +/** + * Plugin manager for migrate source plugins. + * + * @see \Drupal\migrate\Plugin\MigrateSourceInterface + * @see \Drupal\migrate\Plugin\source\SourcePluginBase + * @see \Drupal\migrate\Annotation\MigrateSource + * @see plugin_api + * + * @ingroup migration + */ class MigrateSourcePluginManager extends MigratePluginManager { + /** + * {@inheritdoc} + */ protected function getDiscovery() { if (!$this->discovery) { $discovery = new AnnotatedClassDiscoveryAutomatedProviders($this->subdir, $this->namespaces, $this->pluginDefinitionAnnotationName, $this->additionalAnnotationNamespaces); diff -u b/core/modules/migrate/src/Plugin/NoSourcePluginDecorator.php b/core/modules/migrate/src/Plugin/NoSourcePluginDecorator.php --- b/core/modules/migrate/src/Plugin/NoSourcePluginDecorator.php +++ b/core/modules/migrate/src/Plugin/NoSourcePluginDecorator.php @@ -5,6 +5,9 @@ use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Plugin\Discovery\DiscoveryTrait; +/** + * Remove definitions which refer to a non-existing source plugin. + */ class NoSourcePluginDecorator implements DiscoveryInterface { use DiscoveryTrait; only in patch2: unchanged: --- a/core/lib/Drupal/Component/Annotation/AnnotationInterface.php +++ b/core/lib/Drupal/Component/Annotation/AnnotationInterface.php @@ -13,16 +13,16 @@ public function get(); /** - * Gets the name of the provider of the annotated class. + * Gets the name(s) of the provider(s) of the annotated class. * - * @return string + * @return string|array */ public function getProvider(); /** - * Sets the name of the provider of the annotated class. + * Sets the name(s) of the provider(s) of the annotated class. * - * @param string $provider + * @param string|array $provider */ public function setProvider($provider); only in patch2: unchanged: --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/Discovery/StaticReflectionParser.php @@ -0,0 +1,25 @@ +parentClassName) { + return new static($parser->parentClassName, $finder, $parser->classAnnotationOptimize); + } + } + +}