diff --git a/composer.json b/composer.json
index 874c457..a863c38 100644
--- a/composer.json
+++ b/composer.json
@@ -30,10 +30,10 @@
"zendframework/zend-feed": "2.2.*"
},
"autoload": {
- "psr-0": {
- "Drupal\\Core": "core/lib/",
- "Drupal\\Component": "core/lib/",
- "Drupal\\Driver": "drivers/lib/"
+ "psr-4": {
+ "Drupal\\Core\\": "core/lib/Drupal/Core",
+ "Drupal\\Component\\": "core/lib/Drupal/Component",
+ "Drupal\\Driver\\": "drivers/lib/Drupal/Driver"
},
"files": [
"core/lib/Drupal.php"
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index c4b0cb4..22bae3e 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -2566,7 +2566,10 @@ function drupal_classloader($class_loader = NULL) {
*/
function drupal_classloader_register($name, $path) {
$loader = drupal_classloader();
- $loader->add('Drupal\\' . $name, DRUPAL_ROOT . '/' . $path . '/lib');
+ $loader->addPsr4('Drupal\\' . $name . '\\', array(
+ DRUPAL_ROOT . '/' . $path . '/lib/Drupal/' . $name,
+ DRUPAL_ROOT . '/' . $path . '/lib',
+ ));
}
/**
diff --git a/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php
index b04e39d..b1c0dbf 100644
--- a/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php
+++ b/core/lib/Drupal/Component/Annotation/Plugin/Discovery/AnnotatedClassDiscovery.php
@@ -99,7 +99,6 @@ public function getDefinitions() {
// 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)) {
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS)
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index 0160119..c95a762 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -219,7 +219,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) {
@@ -250,7 +250,6 @@ public function discoverServiceProviders() {
return $serviceProviders;
}
-
/**
* {@inheritdoc}
*/
@@ -411,8 +410,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)) {
@@ -425,9 +424,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);
}
}
@@ -503,14 +502,15 @@ 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;
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 +632,11 @@ protected function storage() {
}
/**
- * Returns the file name for each enabled module.
+ * Gets the file name for each enabled module.
+ *
+ * @return array
+ * Array where each key is a module name, and each value is a path to the
+ * respective *.module or *.profile file.
*/
protected function getModuleFileNames() {
$filenames = array();
@@ -645,18 +649,67 @@ protected function getModuleFileNames() {
}
/**
- * Gets the namespaces of each enabled module.
+ * Gets the PSR-4 base directories for module namespaces.
+ *
+ * @param array $module_file_names
+ * Array where each key is a module name, and each value is a path to the
+ * respective *.module or *.profile file.
+ *
+ * @return array
+ * Array where each key is a module namespace like 'Drupal\system', and each
+ * value is an array of PSR-4 base directories associated with the module
+ * namespace.
+ */
+ protected function getModuleNamespacesPsr4($module_file_names) {
+ $namespaces = array();
+ foreach ($module_file_names as $module => $filename) {
+ // @todo Remove lib/Drupal/$module, once the switch to PSR-4 is complete.
+ $namespaces["Drupal\\$module"][] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib/Drupal/' . $module;
+ $namespaces["Drupal\\$module"][] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib';
+ }
+ return $namespaces;
+ }
+
+ /**
+ * Gets the PSR-0 base directories for module namespaces.
+ *
+ * @param array $module_file_names
+ * Array where each key is a module name, and each value is a path to the
+ * respective *.module or *.profile file.
+ *
+ * @return array
+ * Array where each key is a module namespace like 'Drupal\system', and each
+ * value is a PSR-0 base directory associated with the module namespace.
*/
- protected function getModuleNamespaces($moduleFileNames) {
+ protected function getModuleNamespaces($module_file_names) {
$namespaces = array();
- foreach ($moduleFileNames as $module => $filename) {
+ foreach ($module_file_names as $module => $filename) {
$namespaces["Drupal\\$module"] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib';
}
return $namespaces;
}
/**
- * Registers a list of namespaces.
+ * Registers a list of namespaces with PSR-4 directories for class loading.
+ *
+ * @param array $namespaces
+ * Array where each key is a namespace like 'Drupal\system', and each value
+ * is either a PSR-4 base directory, or an array of PSR-4 base directories
+ * associated with this namespace.
+ */
+ 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 for class loading.
+ *
+ * @param array $namespaces
+ * Array where each key is a namespace like 'Drupal\system', and each value
+ * is either a PSR-0 base directory, or an array of PSR-0 base directories
+ * associated with this namespace.
*/
protected function registerNamespaces(array $namespaces = array()) {
foreach ($namespaces as $prefix => $path) {
diff --git a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php
index 02e96d1..349926c 100644
--- a/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php
+++ b/core/lib/Drupal/Core/Plugin/Discovery/AnnotatedClassDiscovery.php
@@ -16,17 +16,23 @@
class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
/**
- * The subdirectory within a namespace to look for plugins.
+ * A suffix to append to each PSR-4 directory associated with a base
+ * namespace, to form the directories where plugins are found.
*
- * 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 $directorySuffix = '';
+
+ /**
+ * A suffix to append to each base namespace, to obtain the namespaces where
+ * plugins are found.
*
* @var string
*/
- protected $subdir = '';
+ protected $namespaceSuffix = '';
/**
- * An object containing the namespaces to look for plugin implementations.
+ * A list of base namespaces with their PSR-4 directories.
*
* @var \Traversable
*/
@@ -48,7 +54,13 @@ class AnnotatedClassDiscovery extends ComponentAnnotatedClassDiscovery {
*/
function __construct($subdir, \Traversable $root_namespaces, $plugin_definition_annotation_name = 'Drupal\Component\Annotation\Plugin') {
if ($subdir) {
- $this->subdir = str_replace('/', '\\', $subdir);
+ // Prepend a directory separator to $subdir,
+ // if it does not already have one.
+ if ('/' !== $subdir[0]) {
+ $subdir = '/' . $subdir;
+ }
+ $this->directorySuffix = $subdir;
+ $this->namespaceSuffix = str_replace('/', '\\', $subdir);
}
$this->rootNamespacesIterator = $root_namespaces;
$plugin_namespaces = array();
@@ -104,11 +116,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) {
+ // Append the namespace suffix to the base namespace, to obtain the
+ // plugin namespace. E.g. 'Drupal\Views' may become
+ // 'Drupal\Views\Plugin\Block'.
+ $namespace .= $this->namespaceSuffix;
+ foreach ((array) $dirs as $dir) {
+ // Append the directory suffix to the PSR-4 base directory, to obtain
+ // the directory where plugins are found.
+ // E.g. DRUPAL_CORE . 'core/modules/views/lib' may become
+ // DRUPAL_CORE . 'core/modules/views/lib/Plugin/Block'.
+ $plugin_namespaces[$namespace][] = $dir . $this->directorySuffix;
+ }
+ }
+ }
+ else {
+ // Both the namespace suffix and the directory suffix are empty,
+ // so the plugin namespaces and directories are the same as the base
+ // directories.
+ foreach ($this->rootNamespacesIterator as $namespace => $dirs) {
+ $plugin_namespaces[$namespace] = (array) $dirs;
}
- $plugin_namespaces[$namespace] = array($dir);
}
return $plugin_namespaces;
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateActionConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateActionConfigsTest.php
index 3c9c833..e8a8ee7 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateActionConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateActionConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testActionSettings() {
$migration = entity_load('migration', 'd6_action_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ActionSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6ActionSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorConfigsTest.php
index d3cc6a5..e63a8c7 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testAggregatorSettings() {
$migration = entity_load('migration', 'd6_aggregator_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6AggregatorSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6AggregatorSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBookConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBookConfigsTest.php
index 8e52d10..558196f 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBookConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateBookConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testBookSettings() {
$migration = entity_load('migration', 'd6_book_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6BookSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6BookSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php
index 7eb7788..1e90974 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateContactConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testContactSettings() {
$migration = entity_load('migration', 'd6_contact_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ContactSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6ContactSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDblogConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDblogConfigsTest.php
index c761b21..23c534d 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDblogConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateDblogConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testBookSettings() {
$migration = entity_load('migration', 'd6_dblog_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6DblogSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6DblogSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldConfigsTest.php
index 0192130..16b4a66 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFieldConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testFieldSettings() {
$migration = entity_load('migration', 'd6_field_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FieldSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6FieldSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFileConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFileConfigsTest.php
index 2422c4e..9d11f71 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFileConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateFileConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testFileSettings() {
$migration = entity_load('migration', 'd6_file_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6FileSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6FileSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateForumConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateForumConfigsTest.php
index c492a09..44b959c 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateForumConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateForumConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testForumSettings() {
$migration = entity_load('migration', 'd6_forum_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6ForumSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6ForumSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateLocaleConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateLocaleConfigsTest.php
index ff058db..134da4d 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateLocaleConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateLocaleConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testLocaleSettings() {
$migration = entity_load('migration', 'd6_locale_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6LocaleSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6LocaleSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateMenuConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateMenuConfigsTest.php
index ebd83e5..d4bf0b0 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateMenuConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateMenuConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testMenuSettings() {
$migration = entity_load('migration', 'd6_menu_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6MenuSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6MenuSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateNodeConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateNodeConfigsTest.php
index a44b229..c2b3262 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateNodeConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateNodeConfigsTest.php
@@ -27,7 +27,7 @@ public static function getInfo() {
function testNodeSettings() {
$migration = entity_load('migration', 'd6_node_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6NodeSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6NodeSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage);
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php
index 414296f..da14c6c 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSearchConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testSearchSettings() {
$migration = entity_load('migration', 'd6_search_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SearchSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6SearchSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSimpletestConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSimpletestConfigsTest.php
index 8a6fd1e..cb62b00 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSimpletestConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSimpletestConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testSimpletestSettings() {
$migration = entity_load('migration', 'd6_simpletest_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SimpletestSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6SimpletestSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateStatisticsConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateStatisticsConfigsTest.php
index 15da7f1..2029aea 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateStatisticsConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateStatisticsConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testStatisticsSettings() {
$migration = entity_load('migration', 'd6_statistics_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6StatisticsSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6StatisticsSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSyslogConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSyslogConfigsTest.php
index 1f29060..9919335 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSyslogConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSyslogConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testSyslogSettings() {
$migration = entity_load('migration', 'd6_syslog_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SyslogSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6SyslogSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSystemConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSystemConfigsTest.php
index 36b0fa6..55ac976 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSystemConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateSystemConfigsTest.php
@@ -30,7 +30,7 @@ public static function getInfo() {
public function testSystemCron() {
$migration = entity_load('migration', 'd6_system_cron');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemCron.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemCron.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -46,7 +46,7 @@ public function testSystemCron() {
public function testSystemRss() {
$migration = entity_load('migration', 'd6_system_rss');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemRss.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemRss.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -61,7 +61,7 @@ public function testSystemRss() {
public function testSystemPerformance() {
$migration = entity_load('migration', 'd6_system_performance');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemPerformance.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemPerformance.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -78,7 +78,7 @@ public function testSystemPerformance() {
public function testSystemTheme() {
$migration = entity_load('migration', 'd6_system_theme');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemTheme.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemTheme.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -94,7 +94,7 @@ public function testSystemTheme() {
public function testSystemMaintenance() {
$migration = entity_load('migration', 'd6_system_maintenance');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemMaintenance.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemMaintenance.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -110,7 +110,7 @@ public function testSystemMaintenance() {
public function testSystemSite() {
$migration = entity_load('migration', 'd6_system_site');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemSite.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemSite.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -131,7 +131,7 @@ public function testSystemSite() {
public function testSystemFilter() {
$migration = entity_load('migration', 'd6_system_filter');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemFilter.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemFilter.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -146,7 +146,7 @@ public function testSystemFilter() {
public function testSystemImage() {
$migration = entity_load('migration', 'd6_system_image');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemImage.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemImage.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -161,7 +161,7 @@ public function testSystemImage() {
public function testSystemImageGd() {
$migration = entity_load('migration', 'd6_system_image_gd');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemImageGd.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemImageGd.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
@@ -176,7 +176,7 @@ public function testSystemImageGd() {
public function testSystemFile() {
$migration = entity_load('migration', 'd6_system_file');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6SystemFile.php',
+ dirname(__DIR__) . '/Dump/Drupal6SystemFile.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTaxonomyConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTaxonomyConfigsTest.php
index e21e8c4..b1e1887 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTaxonomyConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTaxonomyConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testTaxonomySettings() {
$migration = entity_load('migration', 'd6_taxonomy_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TaxonomySettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6TaxonomySettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTextConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTextConfigsTest.php
index ad96394..9dba4b6 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTextConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateTextConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testTextSettings() {
$migration = entity_load('migration', 'd6_text_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6TextSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6TextSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUpdateConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUpdateConfigsTest.php
index d35ba9a..9de77b1 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUpdateConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUpdateConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testUpdateSettings() {
$migration = entity_load('migration', 'd6_update_settings');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UpdateSettings.php',
+ dirname(__DIR__) . '/Dump/Drupal6UpdateSettings.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserConfigsTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserConfigsTest.php
index 3d35256..7de01d4 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserConfigsTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserConfigsTest.php
@@ -33,7 +33,7 @@ public static function getInfo() {
public function testUserMail() {
$migration = entity_load('migration', 'd6_user_mail');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UserMail.php',
+ dirname(__DIR__) . '/Dump/Drupal6UserMail.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserRoleTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserRoleTest.php
index 19cabeb..f92058a 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserRoleTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateUserRoleTest.php
@@ -28,7 +28,7 @@ function testUserRole() {
/** @var \Drupal\migrate\entity\Migration $migration */
$migration = entity_load('migration', 'd6_user_role');
$dumps = array(
- drupal_get_path('module', 'migrate_drupal') . '/lib/Drupal/migrate_drupal/Tests/Dump/Drupal6UserRole.php',
+ dirname(__DIR__) . '/Dump/Drupal6UserRole.php',
);
$this->prepare($migration, $dumps);
$executable = new MigrateExecutable($migration, new MigrateMessage());
diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module
index bd50676..1b8c282 100644
--- a/core/modules/simpletest/simpletest.module
+++ b/core/modules/simpletest/simpletest.module
@@ -456,21 +456,26 @@ function simpletest_test_get_all($module = NULL) {
);
}
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(
+ $extension_dir . '/lib/Drupal/' . $name . '/Tests',
+ $extension_dir . '/lib/Tests',
+ );
+
+ $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));
+ }
}
}
}
@@ -544,7 +549,11 @@ function simpletest_classloader_register() {
$matches = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.' . $info['extension'] . '$/', $info['dir']);
foreach ($matches as $name => $file) {
drupal_classloader_register($name, dirname($file->uri));
- $classloader->add('Drupal\\' . $name . '\\Tests', DRUPAL_ROOT . '/' . dirname($file->uri) . '/tests');
+ $extension_dir = dirname($file->uri);
+ $classloader->addPsr4('Drupal\\' . $name . '\\Tests\\', array(
+ $extension_dir . '/tests/Drupal/' . $name . '/Tests',
+ $extension_dir . '/tests/lib',
+ ));
// While being there, prime drupal_get_filename().
drupal_get_filename($type, $name, $file->uri);
}
diff --git a/core/modules/simpletest/tests/Drupal/simpletest/Tests/PhpUnitErrorTest.php b/core/modules/simpletest/tests/Drupal/simpletest/Tests/PhpUnitErrorTest.php
index 49fcb02..8e42afe 100644
--- a/core/modules/simpletest/tests/Drupal/simpletest/Tests/PhpUnitErrorTest.php
+++ b/core/modules/simpletest/tests/Drupal/simpletest/Tests/PhpUnitErrorTest.php
@@ -22,7 +22,14 @@ public static function getInfo() {
* Test errors reported.
*/
public function testPhpUnitXmlParsing() {
- require_once __DIR__ . '/../../../../simpletest.module';
+ // This test class could be either in tests/Drupal/simpletest/Tests/, or in
+ // tests/lib/, after the PSR-4 transition.
+ if (file_exists(__DIR__ . '/../../simpletest.module')) {
+ require_once __DIR__ . '/../../simpletest.module';
+ }
+ else {
+ require_once __DIR__ . '/../../../../simpletest.module';
+ }
$phpunit_error_xml = __DIR__ . '/phpunit_error.xml';
$res = simpletest_phpunit_xml_to_rows(1, $phpunit_error_xml);
$this->assertEquals(count($res), 4, 'All testcases got extracted');
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..52bd303 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,7 +57,13 @@ public function setUp() {
'provider' => 'plugin_test',
),
);
- $namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'));
+ $namespaces = new \ArrayObject(array(
+ 'Drupal\plugin_test' => array(
+ // @todo Remove lib/Drupal/$module, once the switch to PSR-4 is complete.
+ DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib/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);
}
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 d61c013..17bbfa5 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,7 +41,13 @@ protected function setUp() {
'provider' => 'plugin_test',
),
);
- $root_namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'));
+ $root_namespaces = new \ArrayObject(array(
+ 'Drupal\plugin_test' => array(
+ // @todo Remove lib/Drupal/$module, once the switch to PSR-4 is complete.
+ DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test',
+ DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib',
+ ),
+ ));
$this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/custom_annotation', $root_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');
$this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $root_namespaces, 'Drupal\plugin_test\Plugin\Annotation\PluginExample');
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 52d4fea..73bc258 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
@@ -70,7 +70,21 @@ protected function setUp() {
'provider' => 'plugin_test',
),
);
- $namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'));
+ // Due to the transition from PSR-0 to PSR-4, plugin classes can be in
+ // either one of
+ // - core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/
+ // - core/modules/system/tests/modules/plugin_test/lib/
+ // To avoid false positives with "Drupal\plugin_test\Drupal\plugin_test\..",
+ // only one of them can be registered.
+ // Note: This precaution is only needed if the plugin namespace is identical
+ // with the module namespace. Usually this is not the case, because every
+ // plugin namespace is like "Drupal\$module\Plugin\..".
+ // @todo Clean this up, once the transition to PSR-4 is complete.
+ $lib_directory = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib';
+ $base_directory = is_dir($lib_directory . '/Drupal/plugin_test')
+ ? $lib_directory . '/Drupal/plugin_test'
+ : $lib_directory;
+ $namespaces = new \ArrayObject(array('Drupal\plugin_test' => $base_directory));
$this->discovery = new AnnotatedClassDiscovery('', $namespaces);
$empty_namespaces = new \ArrayObject();
$this->emptyDiscovery = new AnnotatedClassDiscovery('', $empty_namespaces);
diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist
index 35ff254..5d4aec5 100644
--- a/core/phpunit.xml.dist
+++ b/core/phpunit.xml.dist
@@ -12,7 +12,7 @@
./drush/tests
- ./modules/config/tests/config_test/lib/Drupal/config_test
+ ./modules/config/tests/config_test/lib
diff --git a/core/scripts/switch-psr4.sh b/core/scripts/switch-psr4.sh
new file mode 100644
index 0000000..dd69700
--- /dev/null
+++ b/core/scripts/switch-psr4.sh
@@ -0,0 +1,227 @@
+#!/bin/php
+isDot()) {
+ // do nothing
+ }
+ elseif ($fileinfo->isDir()) {
+ process_candidate_dir($fileinfo->getPathname());
+ }
+ }
+}
+
+/**
+ * Recursively scans a directory for Drupal extensions, and runs
+ * process_extension() for each one that it finds.
+ *
+ * @param string $dir
+ * A directory that could be a Drupal extension directory.
+ */
+function process_candidate_dir($dir) {
+ /**
+ * @var \DirectoryIterator $fileinfo
+ */
+ foreach (new \DirectoryIterator($dir) as $fileinfo) {
+ if ($fileinfo->isDot()) {
+ // Ignore "." and "..".
+ }
+ elseif ($fileinfo->isDir()) {
+ // It's a directory.
+ switch ($fileinfo->getFilename()) {
+ case 'lib':
+ // 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);
+ process_extension_phpunit($extension_name, $dir);
+ }
+}
+
+/**
+ * Process a Drupal extension (module, theme) in a directory.
+ *
+ * This will move all class files in this extension two levels up, from
+ * lib/Drupal/$name/ to lib/.
+ *
+ * @param string $name
+ * Name of the extension.
+ * @param string $dir
+ * Directory of the extension.
+ */
+function process_extension($name, $dir) {
+
+ if (!is_dir($src = "$dir/lib/Drupal/$name")) {
+ // Nothing to do in this module.
+ return;
+ }
+
+ // Move class files two levels up.
+ move_directory_contents($src, "$dir/lib");
+
+ // Clean up.
+ require_dir_empty("$dir/lib/Drupal");
+ rmdir("$dir/lib/Drupal");
+}
+
+/**
+ * Process a Drupal extension (module, theme) in a directory.
+ *
+ * This will move all PHPUnit class files in this extension from
+ * tests/Drupal/$name/Tests/ to tests/lib/.
+ *
+ * @param string $name
+ * Name of the extension.
+ * @param string $dir
+ * Directory of the extension.
+ */
+function process_extension_phpunit($name, $dir) {
+
+ if (!is_dir($src = "$dir/tests/Drupal/$name/Tests")) {
+ // Nothing to do in this module.
+ return;
+ }
+
+ if (!is_dir($dest = "$dir/tests/lib")) {
+ mkdir($dest);
+ }
+
+ // Move class files two levels up.
+ move_directory_contents($src, $dest);
+
+ // Clean up.
+ require_dir_empty("$dir/tests/Drupal/$name");
+ rmdir("$dir/tests/Drupal/$name");
+ require_dir_empty("$dir/tests/Drupal");
+ rmdir("$dir/tests/Drupal");
+}
+
+/**
+ * Move directory contents from an existing source directory to an existing
+ * destination directory.
+ *
+ * @param string $source
+ * An existing source directory.
+ * @param string $destination
+ * An existing destination directory.
+ *
+ * @throws \Exception
+ */
+function move_directory_contents($source, $destination) {
+
+ if (!is_dir($source)) {
+ throw new \Exception("The source '$source' is not a directory.");
+ }
+
+ if (!is_dir($destination)) {
+ throw new \Exception("The destination '$destination' is not a directory.");
+ }
+
+ /**
+ * @var \DirectoryIterator $fileinfo
+ */
+ foreach (new \DirectoryIterator($source) as $fileinfo) {
+ if ($fileinfo->isDot()) {
+ continue;
+ }
+ $dest_path = $destination . '/' . $fileinfo->getFilename();
+ if (!file_exists($dest_path)) {
+ rename($fileinfo->getPathname(), $dest_path);
+ }
+ elseif ($fileinfo->isFile()) {
+ throw new \Exception("Destination '$dest_path' already exists, cannot overwrite.");
+ }
+ elseif ($fileinfo->isDir()) {
+ if (!is_dir($dest_path)) {
+ throw new \Exception("Destination '$dest_path' is not a directory.");
+ }
+ move_directory_contents($fileinfo->getPathname(), $dest_path);
+ }
+ }
+
+ require_dir_empty($source);
+
+ rmdir($source);
+}
+
+/**
+ * Throws an exception if a directory is not empty.
+ *
+ * @param string $dir
+ * Directory to check.
+ *
+ * @throws \Exception
+ */
+function require_dir_empty($dir) {
+ if (is_file($dir)) {
+ throw new \Exception("The path '$dir' is a file, when it should be a directory.");
+ }
+ if (!is_dir($dir)) {
+ throw new \Exception("The directory '$dir' does not exist.");
+ }
+ if (!is_readable($dir)) {
+ throw new \Exception("The directory '$dir' is not readable.");
+ }
+ /**
+ * @var \DirectoryIterator $fileinfo
+ */
+ foreach (new \DirectoryIterator($dir) as $fileinfo) {
+ if ($fileinfo->isDot()) {
+ continue;
+ }
+ $path = $fileinfo->getPathname();
+ if ($fileinfo->isFile()) {
+ throw new \Exception("File '$path' found in a directory that should be empty.");
+ }
+ elseif ($fileinfo->isDir()) {
+ throw new \Exception("Subdirectory '$path' found in a directory that should be empty.");
+ }
+ }
+}
diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php
index c69a52f..f4f9217 100644
--- a/core/tests/bootstrap.php
+++ b/core/tests/bootstrap.php
@@ -59,10 +59,12 @@ function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $l
$lib_path = $dir . '/lib';
if (is_dir($lib_path)) {
$loader->add('Drupal\\' . $extension, $lib_path);
+ $loader->addPsr4('Drupal\\' . $extension . '\\', $lib_path);
}
$tests_path = $dir . '/tests';
if (is_dir($tests_path)) {
$loader->add('Drupal\\' . $extension, $tests_path);
+ $loader->addPsr4('Drupal\\' . $extension . '\Tests\\', $tests_path . '/lib');
}
}
}
diff --git a/core/vendor/composer/autoload_namespaces.php b/core/vendor/composer/autoload_namespaces.php
index f6dbb7c..c7fc2f9 100644
--- a/core/vendor/composer/autoload_namespaces.php
+++ b/core/vendor/composer/autoload_namespaces.php
@@ -30,9 +30,6 @@
'Guzzle\\Common' => array($vendorDir . '/guzzle/common'),
'Gliph' => array($vendorDir . '/sdboyer/gliph/src'),
'EasyRdf_' => array($vendorDir . '/easyrdf/easyrdf/lib'),
- 'Drupal\\Driver' => array($baseDir . '/drivers/lib'),
- 'Drupal\\Core' => array($baseDir . '/core/lib'),
- 'Drupal\\Component' => array($baseDir . '/core/lib'),
'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
'Doctrine\\Common\\Collections\\' => array($vendorDir . '/doctrine/collections/lib'),
diff --git a/core/vendor/composer/autoload_psr4.php b/core/vendor/composer/autoload_psr4.php
index 80607ee..c6ace80 100644
--- a/core/vendor/composer/autoload_psr4.php
+++ b/core/vendor/composer/autoload_psr4.php
@@ -6,4 +6,7 @@
$baseDir = dirname(dirname($vendorDir));
return array(
+ 'Drupal\\Driver\\' => array($baseDir . '/drivers/lib/Drupal/Driver'),
+ 'Drupal\\Core\\' => array($baseDir . '/core/lib/Drupal/Core'),
+ 'Drupal\\Component\\' => array($baseDir . '/core/lib/Drupal/Component'),
);