diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index b125ae8fbba936279ce06c5920854a12b8961afb..3d41fcb419dc37b26a00ee787b48466dd40b4640 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -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'); } /** diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 2b788dccac4bf615837524a8f3585a6870e45fbc..fe43d8647a4e96dcd977347953941b068ee6297d 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -243,7 +243,7 @@ public function discoverServiceProviders() { $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 @@ protected function initializeContainer() { 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 @@ protected function getModuleFileNames() { /** * 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 @@ protected function getModuleNamespaces($module_file_names) { * 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); - } - } } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 914228e98d81bdf6040781f8ac82759fe7e41c0e..bec96c44b3ea4ff2494a727df0e27cb8656cd24f 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -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)); } } diff --git a/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php b/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php index a2fa2992bfb0ba43d8edb82828cf58b2684af922..4e8620a222965b8801e1235cfcdab4f2828f359f 100644 --- a/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php +++ b/core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php @@ -57,13 +57,10 @@ public function setUp() { '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); } diff --git a/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php b/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php index 09358cc38be9368d794ee9f27bb84772205d2c42..76b0b95529a00d3923cc4d5572a65f5382a786d4 100644 --- a/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php +++ b/core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php @@ -41,13 +41,9 @@ protected function setUp() { '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'); diff --git a/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php b/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php index 1071e776c342015ebf0f21258f32419099b6d5ba..f830fc06922f874f719aa3d5d75d90ef9807b162 100644 --- a/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php +++ b/core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php @@ -70,21 +70,10 @@ protected function setUp() { '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); diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/fruit/README.txt b/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/fruit/README.txt index 433798b462ff9c6f3feb01c990a663ba47748440..ce8a86192b1d0fc13e2f92c3363ede0ca0762b9a 100644 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/fruit/README.txt +++ b/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/fruit/README.txt @@ -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 diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist index 32b3384397b1bf1db72e81806935ec498c8d760f..7b8e87c627a1ffdcf06db02089f47bc5c7bb7406 100644 --- a/core/phpunit.xml.dist +++ b/core/phpunit.xml.dist @@ -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> diff --git a/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php b/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php index 5b033f9ffdc84ddd369a9a50db7e66550535c6d2..da65a2f64b08aa18fe133efd0ba1e1484f742d82 100644 --- a/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php +++ b/core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php @@ -32,17 +32,8 @@ public function setUp() { // 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()) diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php index 2953f92b4e569adf1c8a00d5cacc42738e095c77..86cb5cc44495fc476d731cab9c37fa029f9bcb24 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php @@ -64,7 +64,8 @@ protected function setUp() { ), ); - $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'; } /** diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index af5746c7ba352a9925bd4b316845e3c8ecbec9cf..72c5d5bc930047ca11d5bb6f9bb995134fd542d2 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -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'); } }