Issue #2247287 by donquixote: Drop automatic PSR-0 support for modules.
parent
1ab2651755
commit
65b30c0486
|
@ -2028,10 +2028,7 @@ function drupal_classloader($class_loader = NULL) {
|
|||
*/
|
||||
function drupal_classloader_register($name, $path) {
|
||||
$loader = drupal_classloader();
|
||||
$loader->addPsr4('Drupal\\' . $name . '\\', array(
|
||||
DRUPAL_ROOT . '/' . $path . '/lib/Drupal/' . $name,
|
||||
DRUPAL_ROOT . '/' . $path . '/src',
|
||||
));
|
||||
$loader->addPsr4('Drupal\\' . $name . '\\', DRUPAL_ROOT . '/' . $path . '/src');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -243,7 +243,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
$this->moduleList = isset($extensions['module']) ? $extensions['module'] : array();
|
||||
}
|
||||
$module_filenames = $this->getModuleFileNames();
|
||||
$this->registerNamespacesPsr4($this->getModuleNamespacesPsr4($module_filenames));
|
||||
$this->classLoaderAddMultiplePsr4($this->getModuleNamespacesPsr4($module_filenames));
|
||||
|
||||
// Load each module's serviceProvider class.
|
||||
foreach ($this->moduleList as $module => $weight) {
|
||||
|
@ -437,7 +437,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
if (isset($this->container)) {
|
||||
// All namespaces must be registered before we attempt to use any service
|
||||
// from the container.
|
||||
$this->registerNamespacesPsr4($this->container->getParameter('container.namespaces'));
|
||||
$this->classLoaderAddMultiplePsr4($this->container->getParameter('container.namespaces'));
|
||||
}
|
||||
else {
|
||||
$this->container = $this->buildContainer();
|
||||
|
@ -710,40 +710,18 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
/**
|
||||
* Gets the PSR-4 base directories for module namespaces.
|
||||
*
|
||||
* @param array $module_file_names
|
||||
* @param string[] $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
|
||||
* @return string[]
|
||||
* 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.
|
||||
* value is the PSR-4 base directory 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) . '/src';
|
||||
}
|
||||
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($module_file_names) {
|
||||
$namespaces = array();
|
||||
foreach ($module_file_names as $module => $filename) {
|
||||
$namespaces["Drupal\\$module"] = DRUPAL_ROOT . '/' . dirname($filename) . '/lib';
|
||||
$namespaces["Drupal\\$module"] = DRUPAL_ROOT . '/' . dirname($filename) . '/src';
|
||||
}
|
||||
return $namespaces;
|
||||
}
|
||||
|
@ -756,23 +734,10 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
* 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()) {
|
||||
protected function classLoaderAddMultiplePsr4(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) {
|
||||
$this->classLoader->add($prefix, $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -465,29 +465,32 @@ function simpletest_test_get_all($module = NULL) {
|
|||
$all_data += $listing->scan('profile', TRUE);
|
||||
$all_data += $listing->scan('theme', TRUE);
|
||||
}
|
||||
|
||||
// Scan all extension folders for class files.
|
||||
$classes = array();
|
||||
foreach ($all_data as $name => $data) {
|
||||
$extension_dir = DRUPAL_ROOT . '/' . $data->getPath();
|
||||
|
||||
// Build directories in which the test files would reside.
|
||||
$tests_dirs = array(
|
||||
$extension_dir . '/lib/Drupal/' . $name . '/Tests',
|
||||
$extension_dir . '/src/Tests',
|
||||
);
|
||||
// Build the directory in which simpletest test classes would reside.
|
||||
$tests_dir = DRUPAL_ROOT . '/' . $data->getPath() . '/src/Tests';
|
||||
|
||||
// Check if the directory exists.
|
||||
if (!is_dir($tests_dir)) {
|
||||
// This extension has no directory for simpletest cases.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Scan the directory for class files.
|
||||
$files = file_scan_directory($tests_dir, '/\.php$/');
|
||||
if (empty($files)) {
|
||||
// No class files found.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert the file names into the namespaced class names.
|
||||
$strlen = strlen($tests_dir) + 1;
|
||||
$namespace = 'Drupal\\' . $name . '\Tests\\';
|
||||
// Scan it for test files if it exists.
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$classes[] = $namespace . str_replace('/', '\\', substr($file->uri, $strlen, -4));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,13 +57,10 @@ class AnnotatedClassDiscoveryTest extends DiscoveryTestBase {
|
|||
'provider' => 'plugin_test',
|
||||
),
|
||||
);
|
||||
$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/src',
|
||||
),
|
||||
));
|
||||
|
||||
$base_directory = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src';
|
||||
$namespaces = new \ArrayObject(array('Drupal\plugin_test' => $base_directory));
|
||||
|
||||
$this->discovery = new AnnotatedClassDiscovery('Plugin/plugin_test/fruit', $namespaces);
|
||||
$this->emptyDiscovery = new AnnotatedClassDiscovery('Plugin/non_existing_module/non_existing_plugin_type', $namespaces);
|
||||
}
|
||||
|
|
|
@ -41,13 +41,9 @@ class CustomAnnotationClassDiscoveryTest extends DiscoveryTestBase {
|
|||
'provider' => 'plugin_test',
|
||||
),
|
||||
);
|
||||
$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/src',
|
||||
),
|
||||
));
|
||||
|
||||
$base_directory = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src';
|
||||
$root_namespaces = new \ArrayObject(array('Drupal\plugin_test' => $base_directory));
|
||||
|
||||
$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');
|
||||
|
|
|
@ -70,21 +70,10 @@ class CustomDirectoryAnnotatedClassDiscoveryTest extends DiscoveryTestBase {
|
|||
'provider' => 'plugin_test',
|
||||
),
|
||||
);
|
||||
// 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/src/
|
||||
// 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.
|
||||
$extension_dir = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test';
|
||||
$base_directory = is_dir($extension_dir . '/lib/Drupal/plugin_test')
|
||||
? $extension_dir . '/lib/Drupal/plugin_test'
|
||||
: $extension_dir . '/src';
|
||||
|
||||
$base_directory = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src';
|
||||
$namespaces = new \ArrayObject(array('Drupal\plugin_test' => $base_directory));
|
||||
|
||||
$this->discovery = new AnnotatedClassDiscovery('', $namespaces);
|
||||
$empty_namespaces = new \ArrayObject();
|
||||
$this->emptyDiscovery = new AnnotatedClassDiscovery('', $empty_namespaces);
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
The classes in this directory act as a mock plugin type to test annotated class
|
||||
discovery. See the corresponding test file:
|
||||
/core/modules/system/lib/Drupal/system/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php
|
||||
/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
<!-- Exclude Drush tests. -->
|
||||
<exclude>./drush/tests</exclude>
|
||||
<!-- Exclude special-case files from config's test modules. -->
|
||||
<!-- @todo Remove /lib/Drupal/config_test after the transition to PSR-4. -->
|
||||
<exclude>./modules/config/tests/config_test/lib/Drupal/config_test</exclude>
|
||||
<exclude>./modules/config/tests/config_test/src</exclude>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
|
|
@ -32,17 +32,8 @@ abstract class FieldDefinitionTestBase extends UnitTestCase {
|
|||
// getModuleAndPath() returns an array of the module name and directory.
|
||||
list($module_name, $module_dir) = $this->getModuleAndPath();
|
||||
|
||||
$namespaces = new \ArrayObject(
|
||||
array(
|
||||
"Drupal\\$module_name" => array(
|
||||
// Suppport both PSR-0 and PSR-4 directory layouts.
|
||||
$module_dir . '/src',
|
||||
// @todo Remove this when PSR-0 support ends.
|
||||
// @see https://drupal.org/node/2247287
|
||||
$module_dir . '/lib/Drupal/' . $module_name,
|
||||
),
|
||||
)
|
||||
);
|
||||
$namespaces = new \ArrayObject();
|
||||
$namespaces["Drupal\\$module_name"] = $module_dir . '/src';
|
||||
|
||||
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
$language_manager->expects($this->once())
|
||||
|
|
|
@ -64,7 +64,8 @@ class DefaultPluginManagerTest extends UnitTestCase {
|
|||
),
|
||||
);
|
||||
|
||||
$this->namespaces = new \ArrayObject(array('Drupal\plugin_test' => DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/lib'));
|
||||
$this->namespaces = new \ArrayObject();
|
||||
$this->namespaces['Drupal\plugin_test'] = DRUPAL_ROOT . '/core/modules/system/tests/modules/plugin_test/src';
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,21 +56,12 @@ function drupal_phpunit_contrib_extension_directory_roots() {
|
|||
*/
|
||||
function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $loader, $dirs) {
|
||||
foreach ($dirs as $extension => $dir) {
|
||||
// Register PSR-0 test directories.
|
||||
// @todo Remove this, when the transition to PSR-4 is complete.
|
||||
$lib_path = $dir . '/lib';
|
||||
if (is_dir($lib_path)) {
|
||||
$loader->add('Drupal\\' . $extension, $lib_path);
|
||||
}
|
||||
$tests_path = $dir . '/tests';
|
||||
if (is_dir($tests_path)) {
|
||||
$loader->add('Drupal\\' . $extension, $tests_path);
|
||||
}
|
||||
// Register PSR-4 test directories.
|
||||
if (is_dir($dir . '/src')) {
|
||||
// Register the PSR-4 directory for module-provided classes.
|
||||
$loader->addPsr4('Drupal\\' . $extension . '\\', $dir . '/src');
|
||||
}
|
||||
if (is_dir($dir . '/tests/src')) {
|
||||
// Register the PSR-4 directory for PHPUnit test classes.
|
||||
$loader->addPsr4('Drupal\\' . $extension . '\Tests\\', $dir . '/tests/src');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue