Issue #1400748 by Crell, jbrown, plach: Proposal for unified namespace organization.

8.0.x
catch 2012-02-01 12:22:12 +09:00
parent e31452775e
commit 037faa8fbf
51 changed files with 77 additions and 47 deletions

View File

@ -2302,8 +2302,8 @@ function _drupal_bootstrap_configuration() {
// Register explicit vendor namespaces.
$loader->registerNamespaces(array(
// All Symfony-borrowed code lives in /core/includes/Symfony.
'Symfony' => DRUPAL_ROOT . '/core/includes',
// All Symfony-borrowed code lives in /core/vendor/Symfony.
'Symfony' => DRUPAL_ROOT . '/core/vendor',
));
// Register the Drupal namespace for classes in core as a fallback.
// This allows to register additional namespaces within the Drupal namespace
@ -2312,8 +2312,8 @@ function _drupal_bootstrap_configuration() {
// namespace match based on a string comparison. It further allows modules to
// register/overload namespaces in Drupal core.
$loader->registerNamespaceFallbacks(array(
// All Drupal-namespaced code in core lives in /core/includes/Drupal.
'Drupal' => DRUPAL_ROOT . '/core/includes',
// All Drupal-namespaced code in core lives in /core/lib/Drupal.
'Drupal' => DRUPAL_ROOT . '/core/lib',
));
}
@ -3023,7 +3023,7 @@ function drupal_get_complete_schema($rebuild = FALSE) {
*/
function drupal_classloader() {
// Include the Symfony ClassLoader for loading PSR-0-compatible classes.
require_once DRUPAL_ROOT . '/core/includes/Symfony/Component/ClassLoader/UniversalClassLoader.php';
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
@ -3035,7 +3035,7 @@ function drupal_classloader() {
switch (variable_get('autoloader_mode', 'default')) {
case 'apc':
if (function_exists('apc_store')) {
require_once DRUPAL_ROOT . '/core/includes/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
require_once DRUPAL_ROOT . '/core/vendor/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
$loader = new ApcUniversalClassLoader('drupal.' . $GLOBALS['drupal_hash_salt']);
break;
}

View File

@ -8,20 +8,20 @@
/**
* Instantiates and statically caches the correct class for a cache bin.
*
* By default, this returns an instance of the Drupal\Cache\DatabaseBackend
* By default, this returns an instance of the Drupal\Core\Cache\DatabaseBackend
* class.
*
* Classes implementing Drupal\Cache\CacheBackendInterface can register themselves
* both as a default implementation and for specific bins.
* Classes implementing Drupal\Core\Cache\CacheBackendInterface can register
* themselves both as a default implementation and for specific bins.
*
* @param $bin
* The cache bin for which the cache object should be returned, defaults to
* 'cache'.
*
* @return Drupal\Cache\CacheBackendInterface
* @return Drupal\Core\Cache\CacheBackendInterface
* The cache object associated with the specified bin.
*
* @see Drupal\Cache\CacheBackendInterface
* @see Drupal\Core\Cache\CacheBackendInterface
*/
function cache($bin = 'cache') {
// Temporary backwards compatibiltiy layer, allow old style prefixed cache
@ -34,7 +34,7 @@ function cache($bin = 'cache') {
if (!isset($cache_objects[$bin])) {
$class = variable_get('cache_class_' . $bin);
if (!isset($class)) {
$class = variable_get('cache_default_class', 'Drupal\Cache\DatabaseBackend');
$class = variable_get('cache_default_class', 'Drupal\Core\Cache\DatabaseBackend');
}
$cache_objects[$bin] = new $class($bin);
}

View File

@ -277,7 +277,7 @@ function install_begin_request(&$install_state) {
// because any data put in the cache during the installer is inherently
// suspect, due to the fact that Drupal is not fully set up yet.
require_once DRUPAL_ROOT . '/core/includes/cache.inc';
$conf['cache_default_class'] = 'Drupal\\Cache\\InstallBackend';
$conf['cache_default_class'] = 'Drupal\Core\Cache\InstallBackend';
// Prepare for themed output. We need to run this at the beginning of the
// page request to avoid a different theme accidentally getting set. (We also

View File

@ -0,0 +1,8 @@
Drupal Components are independent libraries that do not depend on the rest of
Drupal in order to function. Components MAY depend on other Components, but
that is discouraged. Components MAY NOT depend on any code that is not part of
PHP itself or another Drupal Component.
Each Component should be in its own namespace, and should be as self-contained
as possible. It should be possible to split a Component off to its own
repository and use as a stand-alone library, independently of Drupal.

View File

@ -5,7 +5,7 @@
* Definition of CacheBackendInterface.
*/
namespace Drupal\Cache;
namespace Drupal\Core\Cache;
/**
* Defines an interface for cache implementations.

View File

@ -5,7 +5,7 @@
* Definition of DatabaseBackend.
*/
namespace Drupal\Cache;
namespace Drupal\Core\Cache;
use Exception;
@ -23,7 +23,7 @@ class DatabaseBackend implements CacheBackendInterface {
protected $bin;
/**
* Implements Drupal\Cache\CacheBackendInterface::__construct().
* Implements Drupal\Core\Cache\CacheBackendInterface::__construct().
*/
function __construct($bin) {
// All cache tables should be prefixed with 'cache_', except for the
@ -35,7 +35,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::get().
* Implements Drupal\Core\Cache\CacheBackendInterface::get().
*/
function get($cid) {
$cids = array($cid);
@ -44,7 +44,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::getMultiple().
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
*/
function getMultiple(&$cids) {
try {
@ -114,7 +114,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::set().
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
*/
function set($cid, $data, $expire = CACHE_PERMANENT) {
$fields = array(
@ -143,7 +143,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::delete().
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
*/
function delete($cid) {
db_delete($this->bin)
@ -152,7 +152,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::deleteMultiple().
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
*/
function deleteMultiple(Array $cids) {
// Delete in chunks when a large array is passed.
@ -165,7 +165,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::deletePrefix().
* Implements Drupal\Core\Cache\CacheBackendInterface::deletePrefix().
*/
function deletePrefix($prefix) {
db_delete($this->bin)
@ -174,14 +174,14 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::flush().
* Implements Drupal\Core\Cache\CacheBackendInterface::flush().
*/
function flush() {
db_truncate($this->bin)->execute();
}
/**
* Implements Drupal\Cache\CacheBackendInterface::expire().
* Implements Drupal\Core\Cache\CacheBackendInterface::expire().
*/
function expire() {
if (variable_get('cache_lifetime', 0)) {
@ -216,7 +216,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::garbageCollection().
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection().
*/
function garbageCollection() {
global $user;
@ -236,7 +236,7 @@ class DatabaseBackend implements CacheBackendInterface {
}
/**
* Implements Drupal\Cache\CacheBackendInterface::isEmpty().
* Implements Drupal\Core\Cache\CacheBackendInterface::isEmpty().
*/
function isEmpty() {
$this->garbageCollection();

View File

@ -5,7 +5,7 @@
* Definition of InstallBackend.
*/
namespace Drupal\Cache;
namespace Drupal\Core\Cache;
use Exception;
@ -34,26 +34,26 @@ use Exception;
class InstallBackend extends DatabaseBackend {
/**
* Overrides Drupal\Cache\DatabaseBackend::get().
* Overrides Drupal\Core\Cache\CacheBackendInterface::get().
*/
function get($cid) {
return FALSE;
}
/**
* Overrides Drupal\Cache\DatabaseBackend::getMultiple().
* Overrides Drupal\Core\Cache\CacheBackendInterface::getMultiple().
*/
function getMultiple(&$cids) {
return array();
}
/**
* Overrides Drupal\Cache\DatabaseBackend::set().
* Overrides Drupal\Core\Cache\CacheBackendInterface::set().
*/
function set($cid, $data, $expire = CACHE_PERMANENT) {}
/**
* Implements Drupal\Cache\DatabaseBackend::delete().
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
*/
function delete($cid) {
try {
@ -65,7 +65,7 @@ class InstallBackend extends DatabaseBackend {
}
/**
* Implements Drupal\Cache\DatabaseBackend::deleteMultiple().
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
*/
function deleteMultiple(array $cids) {
try {
@ -77,7 +77,7 @@ class InstallBackend extends DatabaseBackend {
}
/**
* Implements Drupal\Cache\DatabaseBackend::deletePrefix().
* Implements Drupal\Core\Cache\CacheBackendInterface::deletePrefix().
*/
function deletePrefix($prefix) {
try {
@ -89,7 +89,7 @@ class InstallBackend extends DatabaseBackend {
}
/**
* Implements Drupal\Cache\DatabaseBackend::flush().
* Implements Drupal\Core\Cache\CacheBackendInterface::flush().
*/
function flush() {
try {
@ -101,7 +101,7 @@ class InstallBackend extends DatabaseBackend {
}
/**
* Overrides Drupal\Cache\DatabaseBackend::isEmpty().
* Overrides Drupal\Core\Cache\CacheBackendInterface::isEmpty().
*/
function isEmpty() {
return TRUE;

View File

@ -5,7 +5,7 @@
* Definition of NullBackend.
*/
namespace Drupal\Cache;
namespace Drupal\Core\Cache;
/**
* Defines a stub cache implementation.
@ -21,61 +21,61 @@ namespace Drupal\Cache;
class NullBackend implements CacheBackendInterface {
/**
* Implements Drupal\Cache\CacheBackendInterface::__construct().
* Implements Drupal\Core\Cache\CacheBackendInterface::__construct().
*/
function __construct($bin) {}
/**
* Implements Drupal\Cache\CacheBackendInterface::get().
* Implements Drupal\Core\Cache\CacheBackendInterface::get().
*/
function get($cid) {
return FALSE;
}
/**
* Implements Drupal\Cache\CacheBackendInterface::getMultiple().
* Implements Drupal\Core\Cache\CacheBackendInterface::getMultiple().
*/
function getMultiple(&$cids) {
return array();
}
/**
* Implements Drupal\Cache\CacheBackendInterface::set().
* Implements Drupal\Core\Cache\CacheBackendInterface::set().
*/
function set($cid, $data, $expire = CACHE_PERMANENT) {}
/**
* Implements Drupal\Cache\CacheBackendInterface::delete().
* Implements Drupal\Core\Cache\CacheBackendInterface::delete().
*/
function delete($cid) {}
/**
* Implements Drupal\Cache\CacheBackendInterface::deleteMultiple().
* Implements Drupal\Core\Cache\CacheBackendInterface::deleteMultiple().
*/
function deleteMultiple(array $cids) {}
/**
* Implements Drupal\Cache\CacheBackendInterface::deletePrefix().
* Implements Drupal\Core\Cache\CacheBackendInterface::deletePrefix().
*/
function deletePrefix($prefix) {}
/**
* Implements Drupal\Cache\CacheBackendInterface::flush().
* Implements Drupal\Core\Cache\CacheBackendInterface::flush().
*/
function flush() {}
/**
* Implements Drupal\Cache\CacheBackendInterface::expire().
* Implements Drupal\Core\Cache\CacheBackendInterface::expire().
*/
function expire() {}
/**
* Implements Drupal\Cache\CacheBackendInterface::garbageCollection().
* Implements Drupal\Core\Cache\CacheBackendInterface::garbageCollection().
*/
function garbageCollection() {}
/**
* Implements Drupal\Cache\CacheBackendInterface::isEmpty().
* Implements Drupal\Core\Cache\CacheBackendInterface::isEmpty().
*/
function isEmpty() {
return TRUE;

View File

@ -0,0 +1,6 @@
Code in the Drupal\Core namespace represents Drupal Subsystems provided by the
base system. These subsystems MAY depend on Drupal Components and other
Subsystems, but MAY NOT depend on any code in a module.
Each Subsystem should be in its own namespace, and should be as self-contained
as possible.

7
core/lib/README.txt Normal file
View File

@ -0,0 +1,7 @@
The core/lib directory is for classes provided by Drupal Core that are original
to Drupal. All Drupal-originated code must follow the PSR-0 naming convention
for classes and namespaces as documented here:
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
The vendor namespace for Drupal-originated code is "Drupal".

3
core/tests/README.txt Normal file
View File

@ -0,0 +1,3 @@
This directory contains test case code for Drupal core Components and
Subsystems. Test classes should mirror the namespace of the code being tested.
Supporting code for test classes is allowed.

6
core/vendor/README.txt vendored Normal file
View File

@ -0,0 +1,6 @@
3rd party libraries provided by Drupal core should be placed in this directory.
They should not be modified from their original form at any time. They should
be changed only to keep up to date with upstream projects.
Code in this directory MAY be licensed under a GPL-compatible non-GPL license.
If so, it must be properly documented in COPYRIGHT.txt.