Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
Overrides DiscoveryInterface::getDefinitions
public function getDefinitions() {
$definitions = array();
$reader = new AnnotationReader();
// Prevent @endlink from being parsed as an annotation.
$reader
->addGlobalIgnoredName('endlink');
// Register the namespaces of classes that can be used for annotations.
AnnotationRegistry::registerAutoloadNamespaces($this
->getAnnotationNamespaces());
// Search for classes within all PSR-0 namespace locations.
foreach ($this
->getPluginNamespaces() as $namespace => $dirs) {
foreach ($dirs as $dir) {
$dir .= DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $namespace);
if (file_exists($dir)) {
foreach (new DirectoryIterator($dir) as $fileinfo) {
// @todo Once core requires 5.3.6, use $fileinfo->getExtension().
if (pathinfo($fileinfo
->getFilename(), PATHINFO_EXTENSION) == 'php') {
$class = $namespace . '\\' . $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(), $this->pluginDefinitionAnnotationName)) {
// AnnotationInterface::get() returns the array definition
// instead of requiring us to work with the annotation object.
$definition = $annotation
->get();
$definition['class'] = $class;
$definitions[$definition['id']] = $definition;
}
}
}
}
}
}
return $definitions;
}