diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 477b551..5018f3b 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2351,8 +2351,9 @@ function _drupal_bootstrap_database() { // Redirect the user to the installation script if Drupal has not been // installed yet (i.e., if no $databases array has been defined in the // settings.php file) and we are not already installing. - $databases = drupal_container()->getParameter('database.info'); - + if (drupal_container()->hasParameter('database.info')) { + $databases = drupal_container()->getParameter('database.info'); + } if (empty($databases) && !drupal_installation_attempted()) { include_once DRUPAL_ROOT . '/core/includes/install.inc'; install_goto('core/install.php'); @@ -2457,16 +2458,14 @@ function drupal_container(Container $new_container = NULL, $rebuild = FALSE) { ->addArgument('slave') ->addArgument(NULL) ->addArgument('%database.info%'); - $container->register('cache', 'Drupal\Core\Cache\DatabaseBackend') + $container->register('cache.default', 'Drupal\Core\Cache\DatabaseBackend') ->addArgument(new Reference('database')); - $container->register('cache.config', 'Drupal\Core\Cache\DatabaseBackend') - ->addArgument(new Reference('database')) - ->addArgument('config'); + $container->register('cache.factory', 'Drupal\Core\Cache\CacheFactory'); $container ->register('config.storage', 'Drupal\Core\Config\CachedStorage') ->addArgument(new Reference('config.cachedstorage.storage')) - ->addArgument(new Reference('cache.config')); + ->addArgument(new Reference('cache.factory')); // Register configuration object factory. $container->register('config.subscriber.globalconf', 'Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber'); diff --git a/core/includes/cache.inc b/core/includes/cache.inc index 65cc1f5..180eee8 100644 --- a/core/includes/cache.inc +++ b/core/includes/cache.inc @@ -26,13 +26,7 @@ * @see Drupal\Core\Cache\CacheBackendInterface */ function cache($bin = 'cache') { - // Temporary backwards compatibiltiy layer, allow old style prefixed cache - // bin names to be passed as arguments. - $bin = str_replace('cache_', '', $bin); - - $container = drupal_container(); - $service = $container->has("cache.$bin") ? "cache.$bin" : 'cache'; - return $container->get($service)->bin($bin); + return drupal_container()->get('cache.factory')->get($bin); } /** @@ -49,7 +43,7 @@ function cache($bin = 'cache') { * The list of tags to invalidate cache items for. */ function cache_invalidate(array $tags) { - foreach (CacheFactory::getBackends() as $bin => $class) { - cache($bin)->invalidateTags($tags); + foreach (CacheFactory::getBackends() as $bin => $service) { + drupal_container()->get($service)->invalidateTags($tags); } } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 0dbbaa2..763c5ab 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -350,7 +350,8 @@ function install_begin_request(&$install_state) { // suspect, due to the fact that Drupal is not fully set up yet. require_once DRUPAL_ROOT . '/core/includes/cache.inc'; $container = drupal_container(); - $container->register('cache', 'Drupal\Core\Cache\InstallBackend'); + $container->register('cache.default', 'Drupal\Core\Cache\InstallBackend'); + $container->register('cache.factory', 'Drupal\Core\Cache\CacheFactory'); // The install process cannot use the database lock backend since the database // is not fully up, so we use a null backend implementation during the @@ -376,7 +377,7 @@ function install_begin_request(&$install_state) { // Initialize the database system. Note that the connection // won't be initialized until it is actually requested. require_once DRUPAL_ROOT . '/core/includes/database.inc'; - $container->register('cache', 'Drupal\Core\Cache\DatabaseBackend') + $container->register('cache.default', 'Drupal\Core\Cache\DatabaseBackend') ->addArgument(new Reference('database')); // Verify the last completed task in the database, if there is one. diff --git a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php index 06f03f7..cb41ef6 100644 --- a/core/lib/Drupal/Core/Cache/CacheBackendInterface.php +++ b/core/lib/Drupal/Core/Cache/CacheBackendInterface.php @@ -69,6 +69,14 @@ function get($cid); /** + * Sets the cache bin. + * + * @param string $bin + * The name of the cache bin. + */ + function setBin($bin); + + /** * Returns data from the persistent cache when given an array of cache IDs. * * @param $cids diff --git a/core/lib/Drupal/Core/Cache/CacheFactory.php b/core/lib/Drupal/Core/Cache/CacheFactory.php index ba52ea2..f704097 100644 --- a/core/lib/Drupal/Core/Cache/CacheFactory.php +++ b/core/lib/Drupal/Core/Cache/CacheFactory.php @@ -15,9 +15,6 @@ class CacheFactory { /** * Instantiates a cache backend class for a given cache bin. * - * By default, this returns an instance of the - * Drupal\Core\Cache\DatabaseBackend class. - * * Classes implementing Drupal\Core\Cache\CacheBackendInterface can register * themselves both as a default implementation and for specific bins. * @@ -28,11 +25,13 @@ class CacheFactory { * The cache backend object associated with the specified bin. */ public static function get($bin) { - // Check whether there is a custom class defined for the requested bin or + // Check whether there is a custom service defined for the requested bin or // use the default 'cache' definition otherwise. - $cache_backends = self::getBackends(); - $class = isset($cache_backends[$bin]) ? $cache_backends[$bin] : $cache_backends['cache']; - return new $class($bin); + $cache_services = self::getBackends(); + $service = isset($cache_services[$bin]) ? $cache_services[$bin] : $cache_services['cache']; + $backend = drupal_container()->get($service); + $backend->setBin($bin); + return $backend; } /** @@ -43,14 +42,7 @@ public static function get($bin) { * value. */ public static function getBackends() { - $container = drupal_container(); - $cache_services = array_filter($container->getServiceIds(), function ($value) { return substr($value, 0, 6) == 'cache.';}); - $cache_services[] = 'cache'; - $backends = array(); - foreach ($cache_services as $service) { - $backends[$service] = get_class($container->get($service)); - } - return $backends; + return variable_get('cache_services', array('cache' => 'cache.default')); } } diff --git a/core/lib/Drupal/Core/Cache/DatabaseBackend.php b/core/lib/Drupal/Core/Cache/DatabaseBackend.php index 9acd2aa..5a2147b 100644 --- a/core/lib/Drupal/Core/Cache/DatabaseBackend.php +++ b/core/lib/Drupal/Core/Cache/DatabaseBackend.php @@ -34,23 +34,30 @@ class DatabaseBackend implements CacheBackendInterface { protected static $tagCache = array(); /** - * Implements Drupal\Core\Cache\CacheBackendInterface::__construct(). + * Constructs a new cache database backend. + * + * @param Drupal\Core\Database\Connection $connection + * The database connection that should be used. + * @param string $bin + * (optional) The cache bin that should be used. */ function __construct(Connection $connection, $bin = NULL) { $this->dbConnection = $connection; if ($bin) { - $this->bin($bin); + $this->setBin($bin); } } - function bin($bin) { + /** + * Implements Drupal\Core\Cache\CacheBackendInterface::setBin(). + */ + public function setBin($bin) { // All cache tables should be prefixed with 'cache_', except for the // default 'cache' bin. if ($bin != 'cache') { $bin = 'cache_' . $bin; } $this->bin = $bin; - return $this; } /** diff --git a/core/lib/Drupal/Core/Cache/InstallBackend.php b/core/lib/Drupal/Core/Cache/InstallBackend.php index a0b7225..2acfdc4 100644 --- a/core/lib/Drupal/Core/Cache/InstallBackend.php +++ b/core/lib/Drupal/Core/Cache/InstallBackend.php @@ -34,6 +34,12 @@ */ class InstallBackend extends DatabaseBackend { + /** + * Constructs an Drupal\Core\Cache\InstallBackend object. + * + * @param string $bin + * (optional) The cache bin that should be used. + */ function __construct($bin = NULL) { if (class_exists('Drupal\Core\Database\Database') && drupal_container()->hasParameter('database.info')) { $this->dbConnection = Database::getConnection('default', NULL, drupal_container()->getParameter('database.info')); diff --git a/core/lib/Drupal/Core/Cache/MemoryBackend.php b/core/lib/Drupal/Core/Cache/MemoryBackend.php index ce74c2f..fcbdab5 100644 --- a/core/lib/Drupal/Core/Cache/MemoryBackend.php +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php @@ -29,10 +29,9 @@ class MemoryBackend implements CacheBackendInterface { protected $invalidatedTags = array(); /** - * Implements Drupal\Core\Cache\CacheBackendInterface::__construct(). + * Implements Drupal\Core\Cache\CacheBackendInterface::setBin(). */ - public function __construct($bin) { - } + public function setBin($bin) {} /** * Implements Drupal\Core\Cache\CacheBackendInterface::get(). diff --git a/core/lib/Drupal/Core/Config/CachedStorage.php b/core/lib/Drupal/Core/Config/CachedStorage.php index ccbc4c9..d68a733 100644 --- a/core/lib/Drupal/Core/Config/CachedStorage.php +++ b/core/lib/Drupal/Core/Config/CachedStorage.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Config; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Cache\CacheFactory; /** * Defines the cached storage controller. @@ -37,12 +38,12 @@ class CachedStorage implements StorageInterface { * * @param Drupal\Core\Config\StorageInterface $storage * A configuration storage controller to be cached. - * @param Drupal\Core\Cache\CacheBackendInterface $cache + * @param Drupal\Core\Cache\CacheFactory $cache * A cache backend instance to use for caching. */ - public function __construct(StorageInterface $storage, CacheBackendInterface $cache) { + public function __construct(StorageInterface $storage, CacheFactory $factory) { $this->storage = $storage; - $this->cache = $cache; + $this->cache = $factory->get('config'); } /**