diff --git a/core/lib/Drupal/Component/Reflection/MockFileFinder.php b/core/lib/Drupal/Component/Reflection/MockFileFinder.php index 140d190..34c6949 100644 --- a/core/lib/Drupal/Component/Reflection/MockFileFinder.php +++ b/core/lib/Drupal/Component/Reflection/MockFileFinder.php @@ -12,7 +12,7 @@ use Doctrine\Common\Reflection\ClassFinderInterface; /** * Defines a mock file finder that only returns a single filename. * - * This can be used with \Doctrine\Common\Reflection\StaticReflectionParser if + * This can be used with Doctrine\Common\Reflection\StaticReflectionParser if * the filename is known and inheritance is not a concern (for example, if * only the class annotation is needed). */ @@ -32,7 +32,7 @@ class MockFileFinder implements ClassFinderInterface { } /** - * Implements \Doctrine\Common\Reflection\ClassFinderInterface::findFile(). + * Implements Doctrine\Common\Reflection\ClassFinderInterface::findFile(). */ public function findFile($class) { return $this->filename; diff --git a/core/lib/Drupal/Core/Annotation/Plugin.php b/core/lib/Drupal/Core/Annotation/Plugin.php index 708b2b1..cb1ed60 100644 --- a/core/lib/Drupal/Core/Annotation/Plugin.php +++ b/core/lib/Drupal/Core/Annotation/Plugin.php @@ -12,12 +12,11 @@ use Drupal\Core\Annotation\AnnotationInterface; /** * Defines a Plugin annotation object. * - * Annotations in a plugin classes can utilize this class in order to pass - * various metadata about the plugin through the parser to be made available - * during DiscoveryInterface::getDefinitions() calls. This allows the metadata - * of a class to be located with the class itself ensuring that developers do - * not need to hunt through module based info hooks or other methodologies in - * order to find this information. + * Annotations in plugin classes can utilize this class in order to pass + * various metadata about the plugin through the parser to + * DiscoveryInterface::getDefinitions() calls. This allows the metadata + * of a class to be located with the class itself, rather than in module-based + * info hooks. * * @Annotation */ diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index aea8ec2..a8b1643 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -42,13 +42,16 @@ class AnnotatedClassDiscovery implements DiscoveryInterface { public function getDefinitions() { $definitions = array(); $reader = new AnnotationReader(); - // Register namespace of classes that can be used for annotations. + + // Register the namespace of classes that can be used for annotations. AnnotationRegistry::registerAutoloadNamespace('Drupal\Core\Annotation', array(DRUPAL_ROOT . '/core/lib')); // Get all PSR-0 namespaces. $namespaces = drupal_classloader()->getNamespaces(); foreach ($namespaces as $ns => $namespace_dirs) { - // OS Safe directory separators. + + // OS-Safe directory separators. $ns = str_replace('\\', DIRECTORY_SEPARATOR, $ns); + foreach ($namespace_dirs as $dir) { // Check for the pre-determined directory structure to find plugins. $prefix = implode(DIRECTORY_SEPARATOR, array( @@ -58,17 +61,25 @@ class AnnotatedClassDiscovery implements DiscoveryInterface { $this->type )); $dir .= DIRECTORY_SEPARATOR . $prefix; - // If the directory structure exists, look for classes + + // If the directory structure exists, look for classes. if (file_exists($dir)) { $directories = new DirectoryIterator($dir); foreach ($directories as $fileinfo) { - // @todo Once core requires 5.3.6 use $fileinfo->getExtension(). + // @todo Once core requires 5.3.6, use $fileinfo->getExtension(). if (pathinfo($fileinfo->getFilename(), PATHINFO_EXTENSION) == 'php') { - $class = str_replace(DIRECTORY_SEPARATOR, '\\', $prefix . DIRECTORY_SEPARATOR . $fileinfo->getBasename('.php')); - // The file name is already known so no need to find the file, - // but StaticReflectionParser needs one so use a mock version. + $class = str_replace( + DIRECTORY_SEPARATOR, + '\\', + $prefix . DIRECTORY_SEPARATOR . $fileinfo->getBasename('.php') + ); + + // 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 = MockFileFinder::create($fileinfo->getPathName()); $parser = new StaticReflectionParser($class, $finder); + if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass(), 'Drupal\Core\Annotation\Plugin')) { // AnnotationInterface::get() returns the array definition // instead of requiring us to work with the annotation object.