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
9ab046c9
Commit
9ab046c9
authored
Mar 14, 2012
by
catch
Browse files
Issue
#1467126
by Rob Loach, sun, effulgentsia, amateescu, EclipseGc: Provider based
PSR-0
Classes.
parent
1de01b00
Changes
4
Hide whitespace changes
Inline
Side-by-side
core/includes/bootstrap.inc
View file @
9ab046c9
...
...
@@ -2865,15 +2865,15 @@ function drupal_get_complete_schema($rebuild = FALSE) {
* A UniversalClassLoader class instance (or extension thereof).
*/
function
drupal_classloader
()
{
// Include the Symfony ClassLoader for loading PSR-0-compatible classes.
require_once
DRUPAL_ROOT
.
'/core/vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php'
;
// By default, use the UniversalClassLoader which is best for development,
// as it does not break when code is moved on the file system. However, as it
// is slow, allow to use the APC class loader in production.
static
$loader
;
if
(
!
isset
(
$loader
))
{
// Include the Symfony ClassLoader for loading PSR-0-compatible classes.
require_once
DRUPAL_ROOT
.
'/core/vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php'
;
// @todo Use a cleaner way than variable_get() to switch autoloaders.
switch
(
variable_get
(
'autoloader_mode'
,
'default'
))
{
case
'apc'
:
...
...
@@ -2895,6 +2895,19 @@ function drupal_classloader() {
return
$loader
;
}
/**
* Registers an additional namespace.
*
* @param string $name
* The namespace component to register; e.g., 'node'.
* @param string $path
* The relative path to the Drupal component in the filesystem.
*/
function
drupal_classloader_register
(
$name
,
$path
)
{
$loader
=
drupal_classloader
();
$loader
->
registerNamespace
(
'Drupal\\'
.
$name
,
DRUPAL_ROOT
.
'/'
.
$path
.
'/lib'
);
}
/**
* Confirms that an interface is available.
*
...
...
core/includes/module.inc
View file @
9ab046c9
...
...
@@ -140,6 +140,7 @@ function system_list($type) {
// drupal_get_filename() static cache for bootstrap modules only.
// The rest is stored separately to keep the bootstrap module cache small.
foreach
(
$bootstrap_list
as
$module
)
{
drupal_classloader_register
(
$module
->
name
,
dirname
(
$module
->
filename
));
drupal_get_filename
(
'module'
,
$module
->
name
,
$module
->
filename
);
}
// We only return the module names here since module_list() doesn't need
...
...
@@ -175,6 +176,7 @@ function system_list($type) {
}
// Build a list of filenames so drupal_get_filename can use it.
if
(
$record
->
status
)
{
drupal_classloader_register
(
$record
->
name
,
dirname
(
$record
->
filename
));
$lists
[
'filepaths'
][]
=
array
(
'type'
=>
$record
->
type
,
'name'
=>
$record
->
name
,
'filepath'
=>
$record
->
filename
);
}
}
...
...
core/modules/simpletest/tests/module.test
View file @
9ab046c9
...
...
@@ -238,6 +238,38 @@ class ModuleUnitTest extends DrupalWebTestCase {
}
}
/**
* Tests class loading.
*/
class
ModuleClassLoaderTestCase
extends
DrupalWebTestCase
{
protected
$profile
=
'testing'
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Module class loader'
,
'description'
=>
'Tests class loading for modules.'
,
'group'
=>
'Module'
,
);
}
/**
* Tests that module-provided classes can be loaded when a module is enabled.
*/
function
testClassLoading
()
{
$expected
=
'Drupal\\module_autoload_test\\SomeClass::testMethod() was invoked.'
;
module_enable
(
array
(
'module_test'
,
'module_autoload_test'
),
FALSE
);
$this
->
resetAll
();
$this
->
drupalGet
(
'module-test/class-loading'
);
$this
->
assertText
(
$expected
,
t
(
'Autoloader loads classes from an enabled module.'
));
module_disable
(
array
(
'module_autoload_test'
),
FALSE
);
$this
->
resetAll
();
$this
->
drupalGet
(
'module-test/class-loading'
);
$this
->
assertNoText
(
$expected
,
t
(
'Autoloader does not load classes from a disabled module.'
));
}
}
/**
* Unit tests for module installation.
*/
...
...
core/modules/simpletest/tests/module_test.module
View file @
9ab046c9
...
...
@@ -78,6 +78,11 @@ function module_test_menu() {
'page callback'
=>
'module_test_hook_dynamic_loading_invoke_all'
,
'access arguments'
=>
array
(
'access content'
),
);
$items
[
'module-test/class-loading'
]
=
array
(
'title'
=>
'Test loading a class from another module'
,
'page callback'
=>
'module_test_class_loading'
,
'access callback'
=>
TRUE
,
);
return
$items
;
}
...
...
@@ -103,6 +108,21 @@ function module_test_hook_dynamic_loading_invoke_all() {
return
$result
[
'module_test'
];
}
/**
* Page callback for 'class loading' test.
*
* This module does not have a dependency on module_autoload_test.module. If
* that module is enabled, this function should return the string
* 'Drupal\\module_autoload_test\\SomeClass::testMethod() was invoked.'. If
* that module is not enabled, this function should return nothing.
*/
function
module_test_class_loading
()
{
if
(
class_exists
(
'Drupal\module_autoload_test\SomeClass'
))
{
$obj
=
new
Drupal\module_autoload_test\SomeClass
();
return
$obj
->
testMethod
();
}
}
/**
* Implements hook_modules_enabled().
*/
...
...
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