Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
65b30c04
Commit
65b30c04
authored
Jun 01, 2014
by
alexpott
Browse files
Issue
#2247287
by donquixote: Drop automatic
PSR-0
support for modules.
parent
1ab26517
Changes
11
Hide whitespace changes
Inline
Side-by-side
core/includes/bootstrap.inc
View file @
65b30c04
...
...
@@ -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'
);
}
/**
...
...
core/lib/Drupal/Core/DrupalKernel.php
View file @
65b30c04
...
...
@@ -243,7 +243,7 @@ public function discoverServiceProviders() {
$this
->
moduleList
=
isset
(
$extensions
[
'module'
])
?
$extensions
[
'module'
]
:
array
();
}
$module_filenames
=
$this
->
getModuleFileNames
();
$this
->
registerNamespaces
Psr4
(
$this
->
getModuleNamespacesPsr4
(
$module_filenames
));
$this
->
classLoaderAddMultiple
Psr4
(
$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
->
registerNamespaces
Psr4
(
$this
->
container
->
getParameter
(
'container.namespaces'
));
$this
->
classLoaderAddMultiple
Psr4
(
$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
registerNamespaces
Psr4
(
array
$namespaces
=
array
())
{
protected
function
classLoaderAddMultiple
Psr4
(
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
);
}
}
}
core/modules/simpletest/simpletest.module
View file @
65b30c04
...
...
@@ -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
));
}
}
...
...
core/modules/system/src/Tests/Plugin/Discovery/AnnotatedClassDiscoveryTest.php
View file @
65b30c04
...
...
@@ -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
);
}
...
...
core/modules/system/src/Tests/Plugin/Discovery/CustomAnnotationClassDiscoveryTest.php
View file @
65b30c04
...
...
@@ -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'
);
...
...
core/modules/system/src/Tests/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php
View file @
65b30c04
...
...
@@ -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
);
...
...
core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/fruit/README.txt
View file @
65b30c04
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
core/phpunit.xml.dist
View file @
65b30c04
...
...
@@ -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>
...
...
core/tests/Drupal/Tests/Core/Field/FieldDefinitionTestBase.php
View file @
65b30c04
...
...
@@ -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
())
...
...
core/tests/Drupal/Tests/Core/Plugin/DefaultPluginManagerTest.php
View file @
65b30c04
...
...
@@ -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'
;
}
/**
...
...
core/tests/bootstrap.php
View file @
65b30c04
...
...
@@ -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'
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment