diff --git a/core/authorize.php b/core/authorize.php index 8a76fe4..3507f7f 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -23,7 +23,7 @@ // Change the directory to the Drupal root. chdir('..'); -require_once __DIR__ . '/vendor/autoload.php'; +require_once __DIR__ . '/autoload.php'; /** * Global flag to identify update.php and authorize.php runs. diff --git a/core/autoload.php b/core/autoload.php new file mode 100644 index 0000000..4909004 --- /dev/null +++ b/core/autoload.php @@ -0,0 +1,7 @@ +add('Drupal\\' . $name, DRUPAL_ROOT . '/' . $path . '/lib'); + $loader->addPsr4('Drupal\\' . $name . '\\', DRUPAL_ROOT . '/' . $path . '/lib/Drupal/' . $name); + $loader->addPsr4('Drupal\\' . $name . '\\', DRUPAL_ROOT . '/' . $path . '/lib'); + $loader->addPsr4('Drupal\\' . $name . '\\', DRUPAL_ROOT . '/' . $path . '/src'); } /** diff --git a/core/install.php b/core/install.php index 7152fd8..e2900a2 100644 --- a/core/install.php +++ b/core/install.php @@ -8,7 +8,7 @@ // Change the directory to the Drupal root. chdir('..'); -require_once __DIR__ . '/vendor/autoload.php'; +require_once __DIR__ . '/autoload.php'; /** * Global flag to indicate the site is in installation mode. diff --git a/core/lib/Drupal/Component/Plugin/Discovery/AbstractAnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Plugin/Discovery/AbstractAnnotatedClassDiscovery.php new file mode 100644 index 0000000..00ceeb7 --- /dev/null +++ b/core/lib/Drupal/Component/Plugin/Discovery/AbstractAnnotatedClassDiscovery.php @@ -0,0 +1,141 @@ +pluginDefinitionAnnotationName = $plugin_definition_annotation_name; + } + + /** + * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). + */ + public function getDefinition($plugin_id) { + $plugins = $this->getDefinitions(); + return isset($plugins[$plugin_id]) ? $plugins[$plugin_id] : NULL; + } + + /** + * @param $class + * @return bool + */ + public function loadAnnotationClass($class) { + + if (class_exists($class, FALSE)) { + return TRUE; + } + + foreach ($this->getAnnotationNamespaces() as $namespace => $dirs) { + if (0 === strpos($class, $namespace)) { + if (TRUE === $dirs) { + // Use the regular class loader. + return class_exists($class); + } + // Treat $dirs as PSR-4 directories. + $relativePath = str_replace('\\', '/', substr($class, strlen($namespace))) . '.php'; + foreach ((array) $dirs as $dir) { + if (file_exists($file = $dir . '/' . $relativePath)) { + require $file; + return TRUE; + } + } + } + } + + return FALSE; + } + + /** + * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). + */ + public function getDefinitions() { + $definitions = array(); + $reader = new AnnotationReader(); + // Prevent @endlink from being parsed as an annotation. + $reader->addGlobalIgnoredName('endlink'); + $reader->addGlobalIgnoredName('file'); + + // Register the namespaces of classes that can be used for annotations. + AnnotationRegistry::registerLoader(array($this, 'loadAnnotationClass')); + + // Search for classes within all PSR-0 namespace locations. + foreach ($this->getPluginNamespaces() as $namespace => $dirs) { + foreach ($dirs as $dir) { + if (file_exists($dir)) { + /** + * @var DirectoryIterator $fileinfo + */ + 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; + } + } + } + } + } + } + + // Don't let the loaders pile up. + AnnotationRegistry::reset(); + + return $definitions; + } + + /** + * Returns an array of PSR-0 namespaces to search for plugin classes. + */ + protected abstract function getPluginNamespaces(); + + /** + * Returns an array of PSR-0 namespaces to search for annotation classes. + */ + protected abstract function getAnnotationNamespaces(); + +} diff --git a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php index 13f853d..cf33fb8 100644 --- a/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Component/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -7,17 +7,13 @@ namespace Drupal\Component\Plugin\Discovery; -use DirectoryIterator; -use Drupal\Component\Plugin\Discovery\DiscoveryInterface; -use Drupal\Component\Reflection\MockFileFinder; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationRegistry; -use Doctrine\Common\Reflection\StaticReflectionParser; /** * Defines a discovery mechanism to find annotated plugins in PSR-0 namespaces. */ -class AnnotatedClassDiscovery implements DiscoveryInterface { +class AnnotatedClassDiscovery extends AbstractAnnotatedClassDiscovery { /** * The namespaces within which to find plugin classes. @@ -34,16 +30,6 @@ class AnnotatedClassDiscovery implements DiscoveryInterface { protected $annotationNamespaces; /** - * The name of the annotation that contains the plugin definition. - * - * The class corresponding to this name must implement - * \Drupal\Component\Annotation\AnnotationInterface. - * - * @var string - */ - protected $pluginDefinitionAnnotationName; - - /** * Constructs an AnnotatedClassDiscovery object. * * @param array $plugin_namespaces @@ -59,70 +45,18 @@ class AnnotatedClassDiscovery implements DiscoveryInterface { function __construct($plugin_namespaces = array(), $annotation_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { $this->pluginNamespaces = $plugin_namespaces; $this->annotationNamespaces = $annotation_namespaces; - $this->pluginDefinitionAnnotationName = $plugin_definition_annotation_name; - } - - /** - * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition(). - */ - public function getDefinition($plugin_id) { - $plugins = $this->getDefinitions(); - return isset($plugins[$plugin_id]) ? $plugins[$plugin_id] : NULL; - } - - /** - * Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions(). - */ - public function getDefinitions() { - $definitions = array(); - $reader = new AnnotationReader(); - // Prevent @endlink from being parsed as an annotation. - $reader->addGlobalIgnoredName('endlink'); - $reader->addGlobalIgnoredName('file'); - - // 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; + parent::__construct($plugin_definition_annotation_name); } /** - * Returns an array of PSR-0 namespaces to search for plugin classes. + * @inheritdoc */ protected function getPluginNamespaces() { return $this->pluginNamespaces; } /** - * Returns an array of PSR-0 namespaces to search for annotation classes. + * @inheritdoc */ protected function getAnnotationNamespaces() { return $this->annotationNamespaces; diff --git a/core/lib/Drupal/Core/Action/ActionManager.php b/core/lib/Drupal/Core/Action/ActionManager.php index a3bfeda..8013724 100644 --- a/core/lib/Drupal/Core/Action/ActionManager.php +++ b/core/lib/Drupal/Core/Action/ActionManager.php @@ -28,7 +28,7 @@ class ActionManager extends PluginManagerBase { * keyed by the corresponding namespace to look for plugin implementations. */ public function __construct(\Traversable $namespaces) { - $this->discovery = new AnnotatedClassDiscovery('Plugin/Action', $namespaces, array(), 'Drupal\Core\Annotation\Action'); + $this->discovery = new AnnotatedClassDiscovery($namespaces, 'Plugin\Action', 'Drupal\Core\Annotation\Action'); $this->discovery = new AlterDecorator($this->discovery, 'action_info'); $this->factory = new ContainerFactory($this); diff --git a/core/lib/Drupal/Core/Archiver/ArchiverManager.php b/core/lib/Drupal/Core/Archiver/ArchiverManager.php index 14c2a9c..78d431f 100644 --- a/core/lib/Drupal/Core/Archiver/ArchiverManager.php +++ b/core/lib/Drupal/Core/Archiver/ArchiverManager.php @@ -31,7 +31,7 @@ class ArchiverManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Archiver', $namespaces); + parent::__construct($namespaces, 'Plugin\Archiver'); $this->alterInfo($module_handler, 'archiver_info'); $this->setCacheBackend($cache_backend, $language_manager, 'archiver_info'); } diff --git a/core/lib/Drupal/Core/Autoload/ClassLoader.php b/core/lib/Drupal/Core/Autoload/ClassLoader.php new file mode 100644 index 0000000..1e1e1f5 --- /dev/null +++ b/core/lib/Drupal/Core/Autoload/ClassLoader.php @@ -0,0 +1,372 @@ +add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + */ +class ClassLoader { + + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + + const PREDICTOR_INDEX = 9; + + public function getPrefixes() { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + public function getPrefixesPsr4() { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } + else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } + else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } + else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-0 base directories + * @param bool $prepend Whether to prepend the directories + * @throws \Exception + */ + public function addPsr4($prefix, $paths, $prepend = false) { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } + else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } + elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \Exception("A non-empty PSR-4 prefix must end with a namespace separator."); + } + if ($length > self::PREDICTOR_INDEX) { + $predictor = $prefix[0] . $prefix[self::PREDICTOR_INDEX]; + $this->prefixLengthsPsr4[$predictor][$prefix] = $length; + } + else { + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + } + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } + else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } + else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * @throws \Exception + */ + public function setPsr4($prefix, $paths) { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } + else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \Exception("A non-empty PSR-4 prefix must end with a namespace separator."); + } + if ($length > self::PREDICTOR_INDEX) { + $predictor = $prefix[0] . $prefix[self::PREDICTOR_INDEX]; + $this->prefixLengthsPsr4[$predictor][$prefix] = $length; + } + else { + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + } + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() { + return $this->useIncludePath; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) { + if ($file = $this->findFile($class)) { + include $file; + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; + + $first = $class[0]; + if (isset($class[self::PREDICTOR_INDEX])) { + $predictor = $first . $class[self::PREDICTOR_INDEX]; + if (isset($this->prefixLengthsPsr4[$predictor])) { + foreach ($this->prefixLengthsPsr4[$predictor] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + } + + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 + = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR) + ; + } + else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . '.php'; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + + // Remember that this class does not exist. + return $this->classMap[$class] = false; + } +} \ No newline at end of file diff --git a/core/lib/Drupal/Core/Autoload/DrupalAutoloaderInit.php b/core/lib/Drupal/Core/Autoload/DrupalAutoloaderInit.php new file mode 100644 index 0000000..204ec52 --- /dev/null +++ b/core/lib/Drupal/Core/Autoload/DrupalAutoloaderInit.php @@ -0,0 +1,57 @@ +setPsr4('Drupal\Core\\', $baseDir . '/core/lib/Drupal/Core'); + $loader->setPsr4('Drupal\Component\\', $baseDir . '/core/lib/Drupal/Component'); + $loader->setPsr4('Drupal\Driver\\', $baseDir . '/core/lib/Drupal/Driver'); + foreach ($map as $namespace => $path) { + $loader->set($namespace, $path); + } + + $classMap = require $composerDir . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $loader->register(true); + + // @todo This can be updated once Composer provides a autoload_files.php. + require $vendorDir . '/kriswallsmith/assetic/src/functions.php'; + require $baseDir . '/core/lib/Drupal.php'; + + return $loader; + } +} diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index 7f5d630..090ee9a 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -36,10 +36,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac $this->alterInfo($module_handler, 'condition_info'); $this->setCacheBackend($cache_backend, $language_manager, 'condition'); - $annotation_namespaces = array( - 'Drupal\Core\Condition\Annotation' => DRUPAL_ROOT . '/core/lib', - ); - parent::__construct('Plugin/Condition', $namespaces, $annotation_namespaces, 'Drupal\Core\Condition\Annotation\Condition'); + parent::__construct($namespaces, 'Plugin\Condition', 'Drupal\Core\Condition\Annotation\Condition'); + $this->addAnnotationNamespace('Drupal\Core\Condition\Annotation'); } /** diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 1bf9c05..35c18ae 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -19,7 +19,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\TerminableInterface; -use Composer\Autoload\ClassLoader; +use Drupal\Core\Autoload\ClassLoader; /** * The DrupalKernel class is the core of Drupal itself. @@ -97,7 +97,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { /** * The classloader object. * - * @var \Composer\Autoload\ClassLoader + * @var \Drupal\Core\Autoload\ClassLoader */ protected $classLoader; @@ -150,7 +150,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { * String indicating the environment, e.g. 'prod' or 'dev'. Used by * Symfony\Component\HttpKernel\Kernel::__construct(). Drupal does not use * this value currently. Pass 'prod'. - * @param \Composer\Autoload\ClassLoader $class_loader + * @param \Drupal\Core\Autoload\ClassLoader $class_loader * (optional) The classloader is only used if $storage is not given or * the load from storage fails and a container rebuild is required. In * this case, the loaded modules will be registered with this loader in @@ -218,7 +218,7 @@ public function discoverServiceProviders() { $this->moduleList = isset($module_list['enabled']) ? $module_list['enabled'] : array(); } $module_filenames = $this->getModuleFileNames(); - $this->registerNamespaces($this->getModuleNamespaces($module_filenames)); + $this->registerNamespacesPsr4($this->getModuleNamespacesPsr4($module_filenames)); // Load each module's serviceProvider class. foreach ($this->moduleList as $module => $weight) { @@ -402,8 +402,8 @@ protected function initializeContainer() { // All namespaces must be registered before we attempt to use any service // from the container. $container_modules = $this->container->getParameter('container.modules'); - $namespaces_before = $this->classLoader->getPrefixes(); - $this->registerNamespaces($this->getModuleNamespaces($container_modules)); + $namespaces_before = $this->classLoader->getPrefixesPsr4(); + $this->registerNamespacesPsr4($this->getModuleNamespacesPsr4($container_modules)); // If 'container.modules' is wrong, the container must be rebuilt. if (!isset($this->moduleList)) { @@ -416,9 +416,9 @@ protected function initializeContainer() { // registerNamespaces() performs a merge rather than replace, so to // effectively remove erroneous registrations, we must replace them with // empty arrays. - $namespaces_after = $this->classLoader->getPrefixes(); + $namespaces_after = $this->classLoader->getPrefixesPsr4(); $namespaces_before += array_fill_keys(array_diff(array_keys($namespaces_after), array_keys($namespaces_before)), array()); - $this->registerNamespaces($namespaces_before); + $this->registerNamespacesPsr4($namespaces_before); } } @@ -492,14 +492,18 @@ protected function buildContainer() { $container->setParameter('container.modules', $this->getModuleFileNames()); // Get a list of namespaces and put it onto the container. - $namespaces = $this->getModuleNamespaces($this->getModuleFileNames()); + $namespaces = $this->getModuleNamespacesPsr4($this->getModuleFileNames()); // Add all components in \Drupal\Core and \Drupal\Component that have a // Plugin directory. foreach (array('Core', 'Component') as $parent_directory) { $path = DRUPAL_ROOT . '/core/lib/Drupal/' . $parent_directory; + $parent_namespace = 'Drupal\\' . $parent_directory; + /** + * @var \DirectoryIterator $component + */ foreach (new \DirectoryIterator($path) as $component) { if (!$component->isDot() && is_dir($component->getPathname() . '/Plugin')) { - $namespaces['Drupal\\' . $parent_directory .'\\' . $component->getFilename()] = DRUPAL_ROOT . '/core/lib'; + $namespaces[$parent_namespace . '\\' . $component->getFilename()] = $path . '/' . $component->getFilename(); } } } @@ -632,7 +636,30 @@ protected function getModuleFileNames() { } /** - * Gets the namespaces of each enabled module. + * Gets the namespaces of each enabled module, + * each with their PSR-4 directories. + * + * @param array $moduleFileNames + * @return array + */ + protected function getModuleNamespacesPsr4($moduleFileNames) { + $namespaces = array(); + foreach ($moduleFileNames as $module => $filename) { + $namespaces["Drupal\\$module"][] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib/Drupal/' . $module; + // For the time being, register lib and src likewise, + // until this is decided in https://drupal.org/node/1971198 + $namespaces["Drupal\\$module"][] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib'; + $namespaces["Drupal\\$module"][] = DRUPAL_ROOT . '/' . dirname($filename) . '/src'; + } + return $namespaces; + } + + /** + * Gets the namespaces of each enabled module, + * each with its PSR-0 directory. + * + * @param array $moduleFileNames + * @return array */ protected function getModuleNamespaces($moduleFileNames) { $namespaces = array(); @@ -643,7 +670,20 @@ protected function getModuleNamespaces($moduleFileNames) { } /** - * Registers a list of namespaces. + * Registers a list of namespaces with PSR-4 directories. + * + * @param array $namespaces + */ + protected function registerNamespacesPsr4(array $namespaces = array()) { + foreach ($namespaces as $prefix => $paths) { + $this->classLoader->addPsr4($prefix . '\\', $paths); + } + } + + /** + * Registers a list of namespaces with PSR-0 directories. + * + * @param array $namespaces */ protected function registerNamespaces(array $namespaces = array()) { foreach ($namespaces as $prefix => $path) { diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 3060909..5939ab4 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -136,11 +136,11 @@ public function __construct(\Traversable $namespaces, ContainerInterface $contai } protected function doDiscovery($namespaces) { - $annotation_namespaces = array( - 'Drupal\Core\Entity\Annotation' => DRUPAL_ROOT . '/core/lib', - ); - $this->discovery = new AnnotatedClassDiscovery('Entity', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\EntityType'); + $this->discovery = new AnnotatedClassDiscovery($namespaces, 'Entity', 'Drupal\Core\Entity\Annotation\EntityType'); + $this->discovery->addAnnotationNamespace('Drupal\Core\Entity\Annotation'); $this->discovery = new InfoHookDecorator($this->discovery, 'entity_info'); + + // Allow the plugin definition to be altered by hook_entity_info_alter(). $this->discovery = new AlterDecorator($this->discovery, 'entity_info'); $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->id, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); } @@ -192,6 +192,7 @@ public function hasController($entity_type, $controller_type) { * (optional) If this controller definition is nested, the name of the key. * Defaults to NULL. * + * @throws \InvalidArgumentException * @return string * The class name for this controller instance. */ diff --git a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php index 0be215e..6a60cc0 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldTypePluginManager.php @@ -42,10 +42,8 @@ class FieldTypePluginManager extends DefaultPluginManager { * The module handler. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array( - 'Drupal\Core\Entity\Annotation' => DRUPAL_ROOT . '/core/lib', - ); - parent::__construct('Plugin/field/field_type', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\FieldType'); + parent::__construct($namespaces, 'Plugin\field\field_type', 'Drupal\Core\Entity\Annotation\FieldType'); + $this->addAnnotationNamespace('Drupal\Core\Entity\Annotation'); $this->alterInfo($module_handler, 'field_info'); $this->setCacheBackend($cache_backend, $language_manager, 'field_types'); diff --git a/core/lib/Drupal/Core/Menu/LocalActionManager.php b/core/lib/Drupal/Core/Menu/LocalActionManager.php index c99dd83..adf41db 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionManager.php +++ b/core/lib/Drupal/Core/Menu/LocalActionManager.php @@ -65,7 +65,7 @@ class LocalActionManager extends DefaultPluginManager { * The language manager. */ public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { - parent::__construct('Plugin/Menu/LocalAction', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalAction'); + parent::__construct($namespaces, 'Plugin\Menu\LocalAction', 'Drupal\Core\Annotation\Menu\LocalAction'); $this->controllerResolver = $controller_resolver; $this->request = $request; diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 17b5128..9b1bb16 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -73,7 +73,7 @@ class LocalTaskManager extends DefaultPluginManager { * The language manager. */ public function __construct(\Traversable $namespaces, ControllerResolverInterface $controller_resolver, Request $request, RouteProviderInterface $route_provider, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager) { - parent::__construct('Plugin/Menu/LocalTask', $namespaces, array(), 'Drupal\Core\Annotation\Menu\LocalTask'); + parent::__construct($namespaces, 'Plugin\Menu\LocalTask', 'Drupal\Core\Annotation\Menu\LocalTask'); $this->controllerResolver = $controller_resolver; $this->request = $request; $this->routeProvider = $route_provider; diff --git a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php index f802b0c..fec33e0 100644 --- a/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php +++ b/core/lib/Drupal/Core/Plugin/DefaultPluginManager.php @@ -25,6 +25,11 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInterface, CachedDiscoveryInterface { /** + * @var \Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery + */ + protected $originalDiscovery; + + /** * Cached definitions array. * * @var array @@ -91,26 +96,33 @@ class DefaultPluginManager extends PluginManagerBase implements PluginManagerInt /** * Creates the discovery object. * - * @param string|bool $subdir - * The plugin's subdirectory, for example Plugin/views/filter. * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations. - * @param array $annotation_namespaces - * (optional) The namespaces of classes that can be used as annotations. - * Defaults to an empty array. + * @param string|bool $namespace_suffix + * The suffix to append to each of the root namespaces, to obtain the plugin + * namespaces. * @param string $plugin_definition_annotation_name * (optional) The name of the annotation that contains the plugin definition. * Defaults to 'Drupal\Component\Annotation\Plugin'. */ - public function __construct($subdir, \Traversable $namespaces, $annotation_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { - $this->subdir = $subdir; - $this->discovery = new AnnotatedClassDiscovery($subdir, $namespaces, $annotation_namespaces, $plugin_definition_annotation_name); - $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery); + public function __construct(\Traversable $namespaces, $namespace_suffix, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { + $this->originalDiscovery = new AnnotatedClassDiscovery($namespaces, $namespace_suffix, $plugin_definition_annotation_name); + $this->discovery = new ContainerDerivativeDiscoveryDecorator($this->originalDiscovery); $this->factory = new ContainerFactory($this); } /** + * @param string $namespace + * @param bool|string|array $dir + * The PSR-4 directory, or an array of PSR-4 directories, or + * TRUE, to use the regular class loader via class_exists(). + */ + protected function addAnnotationNamespace($namespace, $dir = TRUE) { + $this->originalDiscovery->addAnnotationNamespace($namespace, $dir); + } + + /** * Initialize the cache backend. * * Plugin definitions are cached using the provided cache backend. The diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php index 63c87ab..c283226 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php @@ -7,12 +7,19 @@ namespace Drupal\Core\Plugin\Discovery; -use Drupal\Component\Plugin\Discovery\AnnotatedClassDiscovery as ComponentAnnotatedClassDiscovery; +use Drupal\Component\Plugin\Discovery\AbstractAnnotatedClassDiscovery; /** * Defines a discovery mechanism to find annotated plugins in PSR-0 namespaces. */ -class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery { +class AnnotatedClassDiscovery extends AbstractAnnotatedClassDiscovery { + + /** + * An object containing the namespaces to look for plugin implementations. + * + * @var \Traversable + */ + protected $rootNamespacesIterator; /** * The subdirectory within a namespace to look for plugins. @@ -22,43 +29,63 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery { * * @var string */ - protected $subdir = ''; + protected $directorySuffix = ''; /** - * An object containing the namespaces to look for plugin implementations. + * The subdirectory within a namespace to look for plugins. * - * @var \Traversable + * If the plugins are in the top level of the namespace and not within a + * subdirectory, set this to an empty string. + * + * @var string */ - protected $rootNamespacesIterator; + protected $namespaceSuffix = ''; + + /** + * The namespaces of classes that can be used as annotations. + * + * @var array + */ + protected $annotationNamespaces = array(); /** * Constructs an AnnotatedClassDiscovery object. * - * @param string $subdir - * Either the plugin's subdirectory, for example 'Plugin/views/filter', or - * empty string if plugins are located at the top level of the namespace. * @param \Traversable $root_namespaces * An object that implements \Traversable which contains the root paths * keyed by the corresponding namespace to look for plugin implementations. * If $subdir is not an empty string, it will be appended to each namespace. - * @param array $annotation_namespaces - * (optional) The namespaces of classes that can be used as annotations. - * Defaults to an empty array. + * @param string $namespace_suffix + * Suffix to append to each of the root namespaces, to obtain the plugin + * namespaces. E.g. '\Plugin\views\filter', or empty string if plugins are + * located at the top level of each of the root namespaces. * @param string $plugin_definition_annotation_name * (optional) The name of the annotation that contains the plugin definition. * Defaults to 'Drupal\Component\Annotation\Plugin'. */ - function __construct($subdir, \Traversable $root_namespaces, $annotation_namespaces = array(), $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { - if ($subdir) { - $this->subdir = str_replace('/', '\\', $subdir); - } + public function __construct(\Traversable $root_namespaces, $namespace_suffix = '', $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') { $this->rootNamespacesIterator = $root_namespaces; - $annotation_namespaces += array( - 'Drupal\Component\Annotation' => DRUPAL_ROOT . '/core/lib', - 'Drupal\Core\Annotation' => DRUPAL_ROOT . '/core/lib', - ); - $plugin_namespaces = array(); - parent::__construct($plugin_namespaces, $annotation_namespaces, $plugin_definition_annotation_name); + if ($namespace_suffix) { + if ($namespace_suffix && '\\' !== $namespace_suffix[0]) { + $namespace_suffix = '\\' . $namespace_suffix; + } + $this->namespaceSuffix = $namespace_suffix; + $this->directorySuffix = str_replace('\\', '/', $namespace_suffix); + } + $this->addAnnotationNamespace('Drupal\Component\Annotation'); + $this->addAnnotationNamespace('Drupal\Core\Annotation'); + parent::__construct($plugin_definition_annotation_name); + } + + /** + * @param string $namespace + * The namespace. + * @param bool|string|array $dir + * The PSR-4 directory, or an array of PSR-4 directories, or + * TRUE, to use the regular class loader via class_exists(). + */ + public function addAnnotationNamespace($namespace, $dir = TRUE) { + $this->annotationNamespaces[$namespace] = $dir; } /** @@ -99,14 +126,28 @@ protected function getProviderFromNamespace($namespace) { */ protected function getPluginNamespaces() { $plugin_namespaces = array(); - foreach ($this->rootNamespacesIterator as $namespace => $dir) { - if ($this->subdir) { - $namespace .= "\\{$this->subdir}"; + if ($this->namespaceSuffix) { + foreach ($this->rootNamespacesIterator as $namespace => $dirs) { + $namespace .= $this->namespaceSuffix; + foreach ((array) $dirs as $dir) { + $plugin_namespaces[$namespace][] = $dir . $this->directorySuffix; + } + } + } + else { + foreach ($this->rootNamespacesIterator as $namespace => $dirs) { + $plugin_namespaces[$namespace] = (array) $dirs; } - $plugin_namespaces[$namespace] = array($dir); } return $plugin_namespaces; } + /** + * @inheritdoc + */ + protected function getAnnotationNamespaces() { + return $this->annotationNamespaces; + } + } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index 6f85867..36769fd 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -49,10 +49,8 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac $this->alterInfo($module_handler, 'data_type_info'); $this->setCacheBackend($cache_backend, $language_manager, 'typed_data:types'); - $annotation_namespaces = array( - 'Drupal\Core\TypedData\Annotation' => DRUPAL_ROOT . '/core/lib', - ); - parent::__construct('Plugin/DataType', $namespaces, $annotation_namespaces, 'Drupal\Core\TypedData\Annotation\DataType'); + parent::__construct($namespaces, 'Plugin\DataType', 'Drupal\Core\TypedData\Annotation\DataType'); + $this->addAnnotationNamespace('Drupal\Core\TypedData\Annotation'); } /** diff --git a/core/lib/Drupal/Core/Validation/ConstraintManager.php b/core/lib/Drupal/Core/Validation/ConstraintManager.php index 91551bc..3fe6ace 100644 --- a/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ b/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -47,7 +47,7 @@ class ConstraintManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/Validation/Constraint', $namespaces); + parent::__construct($namespaces, 'Plugin\Validation\Constraint'); $this->discovery = new StaticDiscoveryDecorator($this->discovery, array($this, 'registerDefinitions')); $this->alterInfo($module_handler, 'validation_constraint'); $this->setCacheBackend($cache_backend, $language_manager, 'validation_constraint'); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php index 6362b51..96bcddf 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php @@ -36,11 +36,8 @@ public function __construct($type, \Traversable $namespaces, CacheBackendInterfa 'processor' => 'Drupal\aggregator\Annotation\AggregatorProcessor', ); - $annotation_namespaces = array( - 'Drupal\aggregator\Annotation' => DRUPAL_ROOT . '/core/modules/aggregator/lib', - ); - - parent::__construct("Plugin/aggregator/$type", $namespaces, $annotation_namespaces, $type_annotations[$type]); + parent::__construct($namespaces, "Plugin\\aggregator\\$type", $type_annotations[$type]); + $this->addAnnotationNamespace('Drupal\aggregator\Annotation'); $this->setCacheBackend($cache_backend, $language_manager, "aggregator_$type"); } diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index ead5531..0bc661e 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -35,8 +35,8 @@ class BlockManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\block\Annotation' => $namespaces['Drupal\block']); - parent::__construct('Plugin/Block', $namespaces, $annotation_namespaces, 'Drupal\block\Annotation\Block'); + parent::__construct($namespaces, 'Plugin\Block', 'Drupal\block\Annotation\Block'); + $this->addAnnotationNamespace('Drupal\block\Annotation'); $this->alterInfo($module_handler, 'block'); $this->setCacheBackend($cache_backend, $language_manager, 'block_plugins'); } diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php index dc69f7e..f26238e 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/CKEditorPluginManager.php @@ -33,8 +33,8 @@ class CKEditorPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\ckeditor\Annotation' => $namespaces['Drupal\ckeditor']); - parent::__construct('Plugin/CKEditorPlugin', $namespaces, $annotation_namespaces, 'Drupal\ckeditor\Annotation\CKEditorPlugin'); + parent::__construct($namespaces, 'Plugin\CKEditorPlugin', 'Drupal\ckeditor\Annotation\CKEditorPlugin'); + $this->addAnnotationNamespace('Drupal\ckeditor\Annotation'); $this->alterInfo($module_handler, 'ckeditor_plugin_info'); $this->setCacheBackend($cache_backend, $language_manager, 'ckeditor_plugin'); } diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 04e1291..463f433 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -13,7 +13,7 @@ function comment_uninstall() { variable_del('comment_block_count'); $node_types = array_keys(node_type_get_types()); Drupal::entityManager()->addNamespaces(new ArrayIterator(array( - 'Drupal\comment' => DRUPAL_ROOT . '/core/modules/comment/lib', + 'Drupal\comment' => DRUPAL_ROOT . '/core/modules/comment/lib/Drupal/comment', ))); drupal_classloader_register('comment', 'core/modules/comment'); foreach ($node_types as $node_type) { diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditorManager.php b/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditorManager.php index 79f8013..0e50ac7 100644 --- a/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditorManager.php +++ b/core/modules/edit/lib/Drupal/edit/Plugin/InPlaceEditorManager.php @@ -29,8 +29,8 @@ class InPlaceEditorManager extends PluginManagerBase { * keyed by the corresponding namespace to look for plugin implementations, */ public function __construct(\Traversable $namespaces) { - $annotation_namespaces = array('Drupal\edit\Annotation' => $namespaces['Drupal\edit']); - $this->discovery = new AnnotatedClassDiscovery('Plugin/InPlaceEditor', $namespaces, $annotation_namespaces, 'Drupal\edit\Annotation\InPlaceEditor'); + $this->discovery = new AnnotatedClassDiscovery($namespaces, 'Plugin\InPlaceEditor', 'Drupal\edit\Annotation\InPlaceEditor'); + $this->discovery->addAnnotationNamespace('Drupal\edit\Annotation'); $this->discovery = new AlterDecorator($this->discovery, 'edit_editor'); $this->discovery = new CacheDecorator($this->discovery, 'edit:editor'); $this->factory = new DefaultFactory($this->discovery); diff --git a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php index 9adf267..61aca81 100644 --- a/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php +++ b/core/modules/editor/lib/Drupal/editor/Plugin/EditorManager.php @@ -31,8 +31,8 @@ class EditorManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\editor\Annotation' => $namespaces['Drupal\editor']); - parent::__construct('Plugin/Editor', $namespaces, $annotation_namespaces, 'Drupal\editor\Annotation\Editor'); + parent::__construct($namespaces, 'Plugin\Editor', 'Drupal\editor\Annotation\Editor'); + $this->addAnnotationNamespace('Drupal\editor\Annotation'); $this->alterInfo($module_handler, 'editor_info'); $this->setCacheBackend($cache_backend, $language_manager, 'editor'); } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php index 11582f2..70e90f0 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php @@ -27,8 +27,8 @@ class SelectionPluginManager extends DefaultPluginManager { * {@inheritdoc} */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\entity_reference\Annotation' => $namespaces['Drupal\entity_reference']); - $this->discovery = new AnnotatedClassDiscovery('Plugin/entity_reference/selection', $namespaces, $annotation_namespaces, 'Drupal\entity_reference\Annotation\EntityReferenceSelection'); + $this->discovery = new AnnotatedClassDiscovery($namespaces, 'Plugin\entity_reference\selection', 'Drupal\entity_reference\Annotation\EntityReferenceSelection'); + $this->discovery->addAnnotationNamespace('Drupal\entity_reference\Annotation'); // We're not using the parent constructor because we use a different factory // method and don't need the derivative discovery decorator. diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index c916a9f..f8b2df1 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -54,9 +54,9 @@ class FormatterPluginManager extends DefaultPluginManager { * The 'field type' plugin manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManager $field_type_manager) { - $annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); - parent::__construct('Plugin/field/formatter', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldFormatter'); + parent::__construct($namespaces, 'Plugin\field\formatter', 'Drupal\field\Annotation\FieldFormatter'); + $this->addAnnotationNamespace('Drupal\field\Annotation'); $this->setCacheBackend($cache_backend, $language_manager, 'field_formatter_types'); $this->alterInfo($module_handler, 'field_formatter_info'); diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index 0fe4be9..e7dac34 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -54,9 +54,9 @@ class WidgetPluginManager extends DefaultPluginManager { * The 'field type' plugin manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, LanguageManager $language_manager, FieldTypePluginManager $field_type_manager) { - $annotation_namespaces = array('Drupal\field\Annotation' => $namespaces['Drupal\field']); - parent::__construct('Plugin/field/widget', $namespaces, $annotation_namespaces, 'Drupal\field\Annotation\FieldWidget'); + parent::__construct($namespaces, 'Plugin\field\widget', 'Drupal\field\Annotation\FieldWidget'); + $this->addAnnotationNamespace('Drupal\field\Annotation'); $this->setCacheBackend($cache_backend, $language_manager, 'field_widget_types'); $this->alterInfo($module_handler, 'field_widget_info'); diff --git a/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php b/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php index e2aae54..6892c75 100644 --- a/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php +++ b/core/modules/filter/lib/Drupal/filter/FilterPluginManager.php @@ -39,8 +39,8 @@ class FilterPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\filter\Annotation' => $namespaces['Drupal\filter']); - parent::__construct('Plugin/Filter', $namespaces, $annotation_namespaces, 'Drupal\filter\Annotation\Filter'); + parent::__construct($namespaces, 'Plugin\Filter', 'Drupal\filter\Annotation\Filter'); + $this->addAnnotationNamespace('Drupal\filter\Annotation'); $this->alterInfo($module_handler, 'filter_info'); $this->setCacheBackend($cache_backend, $language_manager, 'filter_plugins', array('filter_formats' => TRUE)); } diff --git a/core/modules/image/lib/Drupal/image/ImageEffectManager.php b/core/modules/image/lib/Drupal/image/ImageEffectManager.php index 64e251e..1bcc028 100644 --- a/core/modules/image/lib/Drupal/image/ImageEffectManager.php +++ b/core/modules/image/lib/Drupal/image/ImageEffectManager.php @@ -21,8 +21,8 @@ class ImageEffectManager extends DefaultPluginManager { * {@inheritdoc} */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\image\Annotation' => $namespaces['Drupal\image']); - parent::__construct('Plugin/ImageEffect', $namespaces, $annotation_namespaces, 'Drupal\image\Annotation\ImageEffect'); + parent::__construct($namespaces, 'Plugin\ImageEffect', 'Drupal\image\Annotation\ImageEffect'); + $this->addAnnotationNamespace('Drupal\image\Annotation'); $this->alterInfo($module_handler, 'image_effect_info'); $this->setCacheBackend($cache_backend, $language_manager, 'image_effect'); diff --git a/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php b/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php new file mode 100644 index 0000000..f169d06 --- /dev/null +++ b/core/modules/layout/lib/Drupal/layout/Plugin/Type/LayoutManager.php @@ -0,0 +1,40 @@ + 'Drupal\layout\Plugin\Layout\StaticLayout', + ); + + /** + * Overrides Drupal\Component\Plugin\PluginManagerBase::__construct(). + * + * @param \Traversable $namespaces + * An object that implements \Traversable which contains the root paths + * keyed by the corresponding namespace to look for plugin implementations, + */ + public function __construct(\Traversable $namespaces) { + // Create layout plugin derivatives from declaratively defined layouts. + $this->discovery = new AnnotatedClassDiscovery($namespaces, 'Plugin\Layout'); + $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); + $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); + + $this->factory = new ReflectionFactory($this->discovery); + } +} diff --git a/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php b/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php index 0ad6b0f..948cad5 100644 --- a/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php +++ b/core/modules/rest/lib/Drupal/rest/Plugin/Type/ResourcePluginManager.php @@ -32,7 +32,7 @@ class ResourcePluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/rest/resource', $namespaces); + parent::__construct($namespaces, 'Plugin\rest\resource'); $this->setCacheBackend($cache_backend, $language_manager, 'rest_plugins'); $this->alterInfo($module_handler, 'rest_resource'); diff --git a/core/modules/search/lib/Drupal/search/SearchPluginManager.php b/core/modules/search/lib/Drupal/search/SearchPluginManager.php index 3821791..b75f934 100644 --- a/core/modules/search/lib/Drupal/search/SearchPluginManager.php +++ b/core/modules/search/lib/Drupal/search/SearchPluginManager.php @@ -28,8 +28,8 @@ class SearchPluginManager extends DefaultPluginManager { * {@inheritdoc} */ public function __construct(\Traversable $namespaces, ConfigFactory $config_factory) { - $annotation_namespaces = array('Drupal\search\Annotation' => $namespaces['Drupal\search']); - parent::__construct('Plugin/Search', $namespaces, $annotation_namespaces, 'Drupal\search\Annotation\SearchPlugin'); + parent::__construct($namespaces, 'Plugin/Search', 'Drupal\search\Annotation\SearchPlugin'); + $this->addAnnotationNamespace('Drupal\search\Annotation'); $this->configFactory = $config_factory; } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 8d441f4..5ab35db 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -454,21 +454,29 @@ function simpletest_test_get_all() { $all_data = $module_data + system_rebuild_theme_data(); $all_data += drupal_system_listing('/\.profile$/', 'profiles', 'name'); foreach ($all_data as $name => $data) { - // Build directory in which the test files would reside. - $tests_dir = DRUPAL_ROOT . '/' . dirname($data->uri) . '/lib/Drupal/' . $name . '/Tests'; + $extension_dir = DRUPAL_ROOT . '/' . dirname($data->uri); + + // Build directories in which the test files would reside. + $tests_dirs = array(); + $tests_dirs[] = $extension_dir . '/lib/Drupal/' . $name . '/Tests'; + $tests_dirs[] = $extension_dir . '/lib/Tests'; + $tests_dirs[] = $extension_dir . '/src/Tests'; + $tests_dirs[] = $extension_dir . '/tests/Drupal/' . $name . '/Tests'; + $tests_dirs[] = $extension_dir . '/tests/lib'; + $tests_dirs[] = $extension_dir . '/tests/src'; + + $namespace = 'Drupal\\' . $name . '\Tests\\'; + // Scan it for test files if it exists. - if (is_dir($tests_dir)) { - $files = file_scan_directory($tests_dir, '/.*\.php/'); - if (!empty($files)) { - $basedir = DRUPAL_ROOT . '/' . dirname($data->uri) . '/lib/'; - foreach ($files as $file) { - // Convert the file name into the namespaced class name. - $replacements = array( - '/' => '\\', - $basedir => '', - '.php' => '', - ); - $classes[] = strtr($file->uri, $replacements); + foreach ($tests_dirs as $tests_dir) { + if (is_dir($tests_dir)) { + $files = file_scan_directory($tests_dir, '/.*\.php/'); + if (!empty($files)) { + $strlen = strlen($tests_dir) + 1; + // Convert the file names into the namespaced class names. + foreach ($files as $file) { + $classes[] = $namespace . str_replace('/', '\\', substr($file->uri, $strlen, -4)); + } } } } @@ -526,8 +534,15 @@ function simpletest_classloader_register() { foreach ($types as $type => $info) { $matches = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.' . $info['extension'] . '$/', $info['dir']); foreach ($matches as $name => $file) { + // @todo Register PSR-4 namespace directories, once our classloader supports it. + // See https://drupal.org/node/2058867 drupal_classloader_register($name, dirname($file->uri)); - $classloader->add('Drupal\\' . $name . '\\Tests', DRUPAL_ROOT . '/' . dirname($file->uri) . '/tests'); + $extension_dir = dirname($file->uri); + $dirs = array(); + $dirs[] = $extension_dir . '/tests/Drupal/' . $name . '/Tests'; + $dirs[] = $extension_dir . '/tests/lib'; + $dirs[] = $extension_dir . '/tests/src'; + $classloader->addPsr4('Drupal\\' . $name . '\\Tests\\', $dirs); // While being there, prime drupal_get_filename(). drupal_get_filename($type, $name, $file->uri); } diff --git a/core/modules/statistics/statistics.php b/core/modules/statistics/statistics.php index ed132e8..22acde2 100644 --- a/core/modules/statistics/statistics.php +++ b/core/modules/statistics/statistics.php @@ -9,7 +9,7 @@ chdir('../../..'); // Load the Drupal bootstrap. -require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php'; +require_once dirname(dirname(__DIR__)) . '/autoload.php'; require_once dirname(dirname(__DIR__)) . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php index dc22c51..6188bef 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php @@ -28,8 +28,8 @@ class ImageToolkitManager extends DefaultPluginManager { * The language manager. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) { - $annotation_namespaces = array('Drupal\system\Annotation' => $namespaces['Drupal\system']); - parent::__construct('Plugin/ImageToolkit', $namespaces, $annotation_namespaces, 'Drupal\system\Annotation\ImageToolkit'); + parent::__construct($namespaces, 'Plugin\ImageToolkit', 'Drupal\system\Annotation\ImageToolkit'); + $this->addAnnotationNamespace('Drupal\system\Annotation'); $this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit'); } diff --git a/core/modules/system/lib/Drupal/system/Plugin/Type/PluginUIManager.php b/core/modules/system/lib/Drupal/system/Plugin/Type/PluginUIManager.php new file mode 100644 index 0000000..971d47d --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Plugin/Type/PluginUIManager.php @@ -0,0 +1,51 @@ +discovery = new AnnotatedClassDiscovery($namespaces, 'Plugin\PluginUI'); + $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); + $this->discovery = new AlterDecorator($this->discovery, 'plugin_ui'); + $this->discovery = new CacheDecorator($this->discovery, 'plugin_ui'); + $this->factory = new DefaultFactory($this->discovery); + } + + /** + * Overrides \Drupal\Component\Plugin\PluginManagerBase::processDefinition(). + */ + public function processDefinition(&$definition, $plugin_id) { + $definition += array( + 'default_task' => TRUE, + 'task_title' => t('View'), + 'task_suffix' => 'view', + 'access_callback' => 'user_access', + ); + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php index d2fba9b..abb8125 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php @@ -57,9 +57,11 @@ public function setUp() { 'provider' => 'plugin_test', ), ); - $namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib')); - $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces); - $this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $namespaces); + $namespaces = new \ArrayObject(array( + 'Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test', + )); + $this->discovery = new AnnotatedClassDiscovery($namespaces, 'Plugin\plugin_test\fruit'); + $this->emptyDiscovery = new AnnotatedClassDiscovery($namespaces, 'Plugin\non_existing_module\non_existing_plugin_type'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php index b572919..674862b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php @@ -41,13 +41,15 @@ protected function setUp() { 'provider' => 'plugin_test', ), ); - $root_namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib')); - $annotation_namespaces = array( - 'Drupal\plugin_test\Plugin\Annotation' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib', - ); + $root_namespaces = new \ArrayObject(array( + 'Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test' + )); + + $this->discovery = new AnnotatedClassDiscovery($root_namespaces, 'Plugin\plugin_test\custom_annotation', 'Drupal\plugin_test\Plugin\Annotation\PluginExample'); + $this->discovery->addAnnotationNamespace('Drupal\plugin_test\Plugin\Annotation'); - $this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/custom_annotation', $root_namespaces, $annotation_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample'); - $this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $root_namespaces, $annotation_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample'); + $this->emptyDiscovery = new AnnotatedClassDiscovery($root_namespaces, 'Plugin\non_existing_module\non_existing_plugin_type', 'Drupal\plugin_test\Plugin\Annotation\PluginExample'); + $this->emptyDiscovery->addAnnotationNamespace('Drupal\plugin_test\Plugin\Annotation'); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php index c005300..f0d3613 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php @@ -39,10 +39,13 @@ protected function setUp() { 'provider' => 'plugin_test', ), ); - $namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib')); - $this->discovery = new AnnotatedClassDiscovery('', $namespaces); + + $namespaces = new \ArrayObject(array( + 'Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test', + )); + $this->discovery = new AnnotatedClassDiscovery($namespaces); $empty_namespaces = new \ArrayObject(); - $this->emptyDiscovery = new AnnotatedClassDiscovery('', $empty_namespaces); + $this->emptyDiscovery = new AnnotatedClassDiscovery($empty_namespaces); } } diff --git a/core/modules/system/tests/http.php b/core/modules/system/tests/http.php index 662031f..10f4e20 100644 --- a/core/modules/system/tests/http.php +++ b/core/modules/system/tests/http.php @@ -18,6 +18,6 @@ // Change current directory to the Drupal root. chdir('../../../..'); -require_once dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php'; +require_once dirname(dirname(dirname(__DIR__))) . '/autoload.php'; require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; drupal_handle_request(TRUE); diff --git a/core/modules/system/tests/https.php b/core/modules/system/tests/https.php index 247e6e5..54c8afa 100644 --- a/core/modules/system/tests/https.php +++ b/core/modules/system/tests/https.php @@ -20,6 +20,6 @@ // Change current directory to the Drupal root. chdir('../../../..'); -require_once dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php'; +require_once dirname(dirname(dirname(__DIR__))) . '/autoload.php'; require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; drupal_handle_request(TRUE); diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 7648ba0..2752cf7 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -14,7 +14,7 @@ */ function taxonomy_uninstall() { Drupal::entityManager()->addNamespaces(new ArrayIterator(array( - 'Drupal\taxonomy' => DRUPAL_ROOT . '/core/modules/taxonomy/lib', + 'Drupal\taxonomy' => DRUPAL_ROOT . '/core/modules/taxonomy/lib/Drupal/taxonomy', ))); drupal_classloader_register('taxonomy', 'core/modules/taxonomy'); // Remove taxonomy_term bundles. diff --git a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php index fb18d3b..88e0784 100644 --- a/core/modules/tour/lib/Drupal/tour/TipPluginManager.php +++ b/core/modules/tour/lib/Drupal/tour/TipPluginManager.php @@ -31,8 +31,8 @@ class TipPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\tour\Annotation' => $namespaces['Drupal\tour']); - parent::__construct('Plugin/tour/tip', $namespaces, $annotation_namespaces, 'Drupal\tour\Annotation\Tip'); + parent::__construct($namespaces, 'Plugin\tour\tip', 'Drupal\tour\Annotation\Tip'); + $this->addAnnotationNamespace('Drupal\tour\Annotation'); $this->alterInfo($module_handler, 'tour_tips_info'); $this->setCacheBackend($cache_backend, $language_manager, 'tour'); 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..c9a15ef 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/Discovery/ViewsHandlerDiscovery.php +++ b/core/modules/views/lib/Drupal/views/Plugin/Discovery/ViewsHandlerDiscovery.php @@ -22,13 +22,6 @@ class ViewsHandlerDiscovery extends AnnotatedClassDiscovery { protected $type; /** - * An object containing the namespaces to look for plugin implementations. - * - * @var \Traversable - */ - protected $rootNamespacesIterator; - - /** * Constructs a ViewsHandlerDiscovery object. * * @param string $type @@ -39,19 +32,9 @@ class ViewsHandlerDiscovery extends AnnotatedClassDiscovery { */ 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'; + parent::__construct($root_namespaces, 'Plugin\views\\' . $type, 'Drupal\Component\Annotation\PluginID'); + unset($this->annotationNamespaces['Drupal\Core\Annotation']); } /** @@ -66,16 +49,4 @@ public function getDefinitions() { return $definitions; } - /** - * {@inheritdoc} - */ - protected function getPluginNamespaces() { - $plugin_namespaces = array(); - foreach ($this->rootNamespacesIterator as $namespace => $dir) { - $plugin_namespaces["$namespace\\Plugin\\views\\{$this->type}"] = array($dir); - } - - return $plugin_namespaces; - } - } diff --git a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php index d603fba..4404bf5 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php +++ b/core/modules/views/lib/Drupal/views/Plugin/ViewsPluginManager.php @@ -34,9 +34,9 @@ class ViewsPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct($type, \Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ModuleHandlerInterface $module_handler) { - $annotation_namespaces = array('Drupal\views\Annotation' => $namespaces['Drupal\views']); $plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($type); - parent::__construct("Plugin/views/$type", $namespaces, $annotation_namespaces, $plugin_definition_annotation_name); + parent::__construct($namespaces, "Plugin\\views\\$type", $plugin_definition_annotation_name); + $this->addAnnotationNamespace('Drupal\views\Annotation'); $this->defaults += array( 'parent' => 'parent', diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 31ea371..d274252 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -4,7 +4,7 @@ * This script runs Drupal tests from command line. */ -require_once __DIR__ . '/../vendor/autoload.php'; +require_once __DIR__ . '/../autoload.php'; use Drupal\Core\StreamWrapper\PublicStream; diff --git a/core/scripts/switch-psr4.sh b/core/scripts/switch-psr4.sh new file mode 100644 index 0000000..3cec824 --- /dev/null +++ b/core/scripts/switch-psr4.sh @@ -0,0 +1,108 @@ +#!/bin/php +isDot()) { + // do nothing + } + elseif ($fileinfo->isDir()) { + process_candidate_dir($fileinfo->getPathname()); + } + } +} + +function process_candidate_dir($dir) { + foreach (new \DirectoryIterator($dir) as $fileinfo) { + if ($fileinfo->isDot()) { + // Ignore "." and "..". + } + elseif ($fileinfo->isDir()) { + // It's a directory. + switch ($fileinfo->getFilename()) { + case 'lib': + case 'src': + case 'module_autoload_test': + // Ignore these directory names. + continue; + default: + // Look for more extensions in subdirectories. + process_candidate_dir($fileinfo->getPathname()); + } + } + else { + // It's a file. + if (preg_match('/^(.+).info.yml$/', $fileinfo->getFilename(), $m)) { + // It's a *.info.yml file, so we found an extension directory. + $extension_name = $m[1]; + } + } + } + if (isset($extension_name)) { + process_extension($extension_name, $dir); + } +} + +function process_extension($name, $dir) { + + // Move main module class files. + if (is_dir("$dir/lib/Drupal/$name")) { + // This is a module directory with a PSR-0 /lib/ folder. + if (!is_dir($dir . '/src')) { + mkdir($dir . '/src'); + } + rename("$dir/lib/Drupal/$name", "$dir/src"); + } + + // Move class files in tests directory. + if (is_dir("$dir/tests/Drupal/$name/Tests")) { + rename("$dir/tests/Drupal/$name/Tests", "$dir/tests/src"); + } + + // Clean up empty directories. + foreach (array( + "lib/Drupal/$name", + 'lib/Drupal', + 'lib', + "tests/Drupal/$name/Tests", + "tests/Drupal/$name", + "tests/Drupal", + ) as $subdir) { + if (is_dir_empty("$dir/$subdir")) { + rmdir("$dir/$subdir"); + } + } +} + +function is_dir_empty($dir) { + if (!is_readable($dir)) { + return NULL; + } + $handle = opendir($dir); + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + return FALSE; + } + } + return TRUE; +} diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 66c4be4..e0be3f8 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -1,7 +1,7 @@ add('Drupal\\Tests', __DIR__); foreach (scandir(__DIR__ . "/../modules") as $module) { diff --git a/core/update.php b/core/update.php index ac36b2a..0238871 100644 --- a/core/update.php +++ b/core/update.php @@ -22,7 +22,7 @@ // Change the directory to the Drupal root. chdir('..'); -require_once __DIR__ . '/vendor/autoload.php'; +require_once __DIR__ . '/autoload.php'; // Exit early if an incompatible PHP version would cause fatal errors. // The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not diff --git a/index.php b/index.php index 426aa22..5f5ada6 100644 --- a/index.php +++ b/index.php @@ -8,7 +8,7 @@ * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory. */ -require_once __DIR__ . '/core/vendor/autoload.php'; +require_once __DIR__ . '/core/autoload.php'; require_once __DIR__ . '/core/includes/bootstrap.inc'; try {