Unverified Commit 9b92d624 authored by damiankloip's avatar damiankloip Committed by damiankloip
Browse files

Issue #2996626 by Fabianx, damiankloip: Follow-up; class renames

parent a815d073
......@@ -156,13 +156,13 @@ if ($memcache_exists || $memcached_exists) {
'class' => 'Drupal\Core\Site\Settings',
'factory' => 'Drupal\Core\Site\Settings::getInstance',
],
'memcache.config' => [
'class' => 'Drupal\memcache\DrupalMemcacheConfig',
'memcache.settings' => [
'class' => 'Drupal\memcache\MemcacheSettings',
'arguments' => ['@settings'],
],
'memcache.backend.cache.factory' => [
'class' => 'Drupal\memcache\DrupalMemcacheFactory',
'arguments' => ['@memcache.config']
'class' => 'Drupal\memcache\Driver\MemcacheDriverFactory',
'arguments' => ['@memcache.settings']
],
'memcache.backend.cache.container' => [
'class' => 'Drupal\memcache\DrupalMemcacheFactory',
......
services:
memcache.config:
class: Drupal\memcache\DrupalMemcacheConfig
memcache.settings:
class: Drupal\memcache\MemcacheSettings
arguments: ['@settings']
memcache.factory:
class: Drupal\memcache\DrupalMemcacheFactory
arguments: ['@memcache.config']
class: Drupal\memcache\Driver\MemcacheDriverFactory
arguments: ['@memcache.settings']
cache.backend.memcache:
class: Drupal\memcache\MemcacheBackendFactory
arguments: ['@memcache.factory', '@cache_tags.invalidator.checksum']
......
<?php
namespace Drupal\memcache\Driver;
namespace Drupal\memcache\Connection;
use Drupal\memcache\DrupalMemcacheConfig;
use Drupal\memcache\Connection\MemcacheConnectionInterface;
class MemcacheConnection implements MemcacheConnectionInterface {
......
<?php
namespace Drupal\memcache\Driver;
namespace Drupal\memcache\Connection;
interface MemcacheConnectionInterface {
......
<?php
namespace Drupal\memcache\Driver;
namespace Drupal\memcache\Connection;
use Drupal\memcache\DrupalMemcacheConfig;
use Drupal\memcache\Connection\MemcacheConnectionInterface;
use Drupal\memcache\MemcacheSettings;
class MemcachedConnection implements MemcacheConnectionInterface {
......@@ -16,10 +17,10 @@ class MemcachedConnection implements MemcacheConnectionInterface {
/**
* Constructs a MemcachedConnection object.
*
* @param \Drupal\memcache\DrupalMemcacheConfig $settings
* @param \Drupal\memcache\MemcacheSettings $settings
* The memcache config object.
*/
public function __construct(DrupalMemcacheConfig $settings) {
public function __construct(MemcacheSettings $settings) {
$this->memcache = new \Memcached();
$default_opts = [
......
<?php
/**
* @file
* Contains \Drupal\memcache\DrupalMemcacheBase.
*/
namespace Drupal\memcache;
namespace Drupal\memcache\Driver;
use Drupal\Component\Utility\Timer;
use Drupal\memcache\MemcacheSettings;
use Drupal\memcache\DrupalMemcacheInterface;
/**
* Class DrupalMemcacheBase.
* Class DriverBase.
*/
abstract class DrupalMemcacheBase implements DrupalMemcacheInterface {
abstract class DriverBase implements DrupalMemcacheInterface {
/**
* The memcache config object.
*
* @var \Drupal\memcache\DrupalMemcacheConfig
* @var \Drupal\memcache\MemcacheSettings
*/
protected $settings;
......@@ -56,14 +53,14 @@ abstract class DrupalMemcacheBase implements DrupalMemcacheInterface {
/**
* Constructs a DrupalMemcacheBase object.
*
* @param \Drupal\memcache\DrupalMemcacheConfig
* @param \Drupal\memcache\MemcacheSettings
* The memcache config object.
* @param \Memcached|\Memcache $connection
* An existing memcache connection object.
* @param string $bin
* The class instance specific cache bin to use.
*/
public function __construct(DrupalMemcacheConfig $settings, $memcache, $bin = NULL) {
public function __construct(MemcacheSettings $settings, $memcache, $bin = NULL) {
$this->settings = $settings;
$this->memcache = $memcache;
......
<?php
/**
* @file
* Contains \Drupal\memcache\DrupalMemcache.
*/
namespace Drupal\memcache;
use Psr\Log\LogLevel;
use Drupal\Component\Utility\Timer;
namespace Drupal\memcache\Driver;
/**
* Class DrupalMemcache.
* Class MemcacheDriver.
*/
class DrupalMemcache extends DrupalMemcacheBase {
class MemcacheDriver extends DriverBase {
/**
* {@inheritdoc}
......
<?php
/**
* @file
* Contains \Drupal\memcache\DrupalMemcacheFactory.
*/
namespace Drupal\memcache;
namespace Drupal\memcache\Driver;
use Psr\Log\LogLevel;
use Drupal\memcache\Driver\MemcacheConnection;
use Drupal\memcache\Driver\MemcachedConnection;
use Drupal\memcache\Connection\MemcacheConnection;
use Drupal\memcache\Connection\MemcachedConnection;
use Drupal\memcache\MemcacheSettings;
use Drupal\memcache\MemcacheException;
/**
* Factory class for creation of Memcache objects.
*/
class DrupalMemcacheFactory {
class MemcacheDriverFactory {
/**
* The settings object.
*
* @var \Drupal\memcache\DrupalMemcacheConfig
* @var \Drupal\memcache\MemcacheSettings
*/
protected $settings;
/**
* @var string
*/
protected $driverClass;
protected $connectionClass;
/**
* @var string
*/
protected $drupalClass;
protected $driverClass;
/**
* @var bool
*/
protected $memcachePersistent;
protected $persistent;
/**
* @var \Drupal\memcache\Driver\MemcacheConnectionInterface[]
* @var \Drupal\memcache\Connection\MemcacheConnectionInterface[]
*/
protected $memcacheCache = [];
protected $connections = [];
/**
* @var array
*/
protected $memcacheServers = [];
protected $servers = [];
/**
* @var array
*/
protected $memcacheBins = [];
protected $bins = [];
/**
* @var array
......@@ -62,9 +57,9 @@ class DrupalMemcacheFactory {
/**
* Constructs a DrupalMemcacheFactory object.
*
* @param \Drupal\memcache\DrupalMemcacheConfig $settings
* @param \Drupal\memcache\MemcacheSettings $settings
*/
public function __construct(DrupalMemcacheConfig $settings) {
public function __construct(MemcacheSettings $settings) {
$this->settings = $settings;
$this->initialize();
......@@ -87,30 +82,30 @@ class DrupalMemcacheFactory {
$this->flush();
}
if (empty($this->memcacheCache) || empty($this->memcacheCache[$bin])) {
// If there is no cluster for this bin in $memcache_bins, cluster is
if (empty($this->connections) || empty($this->connections[$bin])) {
// If there is no cluster for this bin in $bins, cluster is
// 'default'.
$cluster = empty($this->memcacheBins[$bin]) ? 'default' : $this->memcacheBins[$bin];
$cluster = empty($this->bins[$bin]) ? 'default' : $this->bins[$bin];
// If this bin isn't in our $memcacheBins configuration array, and the
// If this bin isn't in our $bins configuration array, and the
// 'default' cluster is already initialized, map the bin to 'default'
// because we always map the 'default' bin to the 'default' cluster.
if (empty($this->memcacheBins[$bin]) && !empty($this->memcacheCache['default'])) {
$this->memcacheCache[$bin] = &$this->memcacheCache['default'];
if (empty($this->bins[$bin]) && !empty($this->connections['default'])) {
$this->connections[$bin] = &$this->connections['default'];
}
else {
// Create a new Memcache object. Each cluster gets its own Memcache
// object.
/** @var \Drupal\memcache\Driver\MemcacheConnectionInterface $memcache */
$memcache = new $this->driverClass($this->settings);
/** @var \Drupal\memcache\Connection\MemcacheConnectionInterface $memcache */
$memcache = new $this->connectionClass($this->settings);
// A variable to track whether we've connected to the first server.
$init = FALSE;
// Link all the servers to this cluster.
foreach ($this->memcacheServers as $s => $c) {
foreach ($this->servers as $s => $c) {
if ($c == $cluster && !isset($this->failedConnectionCache[$s])) {
if ($memcache->addServer($s, $this->memcachePersistent) && !$init) {
if ($memcache->addServer($s, $this->persistent) && !$init) {
$init = TRUE;
}
......@@ -122,14 +117,14 @@ class DrupalMemcacheFactory {
if ($init) {
// Map the current bin with the new Memcache object.
$this->memcacheCache[$bin] = $memcache;
$this->connections[$bin] = $memcache;
// Now that all the servers have been mapped to this cluster, look for
// other bins that belong to the cluster and map them too.
foreach ($this->memcacheBins as $b => $c) {
foreach ($this->bins as $b => $c) {
if (($c == $cluster) && ($b != $bin)) {
// Map this bin and cluster by reference.
$this->memcacheCache[$b] = &$this->memcacheCache[$bin];
$this->connections[$b] = &$this->connections[$bin];
}
}
}
......@@ -139,7 +134,7 @@ class DrupalMemcacheFactory {
}
}
return empty($this->memcacheCache[$bin]) ? FALSE : new $this->drupalClass($this->settings, $this->memcacheCache[$bin]->getMemcache(), $bin);
return empty($this->connections[$bin]) ? FALSE : new $this->driverClass($this->settings, $this->connections[$bin]->getMemcache(), $bin);
}
/**
......@@ -164,34 +159,34 @@ class DrupalMemcacheFactory {
}
// @todo Make driver class configurable?
$this->driverClass = MemcachedConnection::class;
$this->drupalClass = DrupalMemcached::class;
$this->connectionClass = MemcachedConnection::class;
$this->driverClass = MemcachedDriver::class;
if ($extension === \Memcache::class) {
$this->driverClass = MemcacheConnection::class;
$this->drupalClass = DrupalMemcache::class;
$this->connectionClass = MemcacheConnection::class;
$this->driverClass = MemcacheDriver::class;
}
// Values from settings.php
$this->memcacheServers = $this->settings->get('servers', ['127.0.0.1:11211' => 'default']);
$this->memcacheBins = $this->settings->get('bins', ['default' => 'default']);
$this->servers = $this->settings->get('servers', ['127.0.0.1:11211' => 'default']);
$this->bins = $this->settings->get('bins', ['default' => 'default']);
// Indicate whether to connect to memcache using a persistent connection.
// Note: this only affects the Memcache PECL extension, and does not affect
// the Memcached PECL extension. For a detailed explanation see:
// http://drupal.org/node/822316#comment-4427676
$this->memcachePersistent = $this->settings->get('persistent', FALSE);
$this->persistent = $this->settings->get('persistent', FALSE);
}
/**
* Flushes the memcache bin/server/cache mappings and closes connections.
*/
protected function flush() {
foreach ($this->memcacheCache as $cluster) {
foreach ($this->connections as $cluster) {
$cluster->close();
}
$this->memcacheCache = [];
$this->connections = [];
}
}
<?php
/**
* @file
* Contains \Drupal\memcache\DrupalMemcached.
*/
namespace Drupal\memcache;
use Drupal\Component\Utility\Timer;
namespace Drupal\memcache\Driver;
/**
* Class DrupalMemcached.
* Class MemcachedDriver.
*/
class DrupalMemcached extends DrupalMemcacheBase {
class MemcachedDriver extends DriverBase {
/**
* {@inheritdoc}
......
......@@ -7,7 +7,7 @@
namespace Drupal\memcache\Lock;
use Drupal\memcache\DrupalMemcacheFactory;
use Drupal\memcache\Driver\MemcacheDriverFactory;
/**
* THe memcache lock factory.
......@@ -24,16 +24,16 @@ class MemcacheLockFactory {
/**
* The memcache factory.
*
* @var \Drupal\memcache\DrupalMemcacheFactory
* @var \Drupal\memcache\Driver\MemcacheDriverFactory
*/
protected $factory;
/**
* Constructs a new MemcacheLockBackend.
*
* @param \Drupal\memcache\DrupalMemcacheFactory $memcache_factory
* @param \Drupal\memcache\Driver\MemcacheDriverFactory $memcache_factory
*/
public function __construct(DrupalMemcacheFactory $memcache_factory) {
public function __construct(MemcacheDriverFactory $memcache_factory) {
$this->factory = $memcache_factory;
}
......
......@@ -9,6 +9,7 @@ namespace Drupal\memcache;
use Drupal\Core\Cache\CacheFactoryInterface;
use Drupal\Core\Cache\CacheTagsChecksumInterface;
use Drupal\memcache\Driver\MemcacheDriverFactory;
/**
* Class MemcacheBackendFactory.
......@@ -18,7 +19,7 @@ class MemcacheBackendFactory implements CacheFactoryInterface {
/**
* The memcache factory object.
*
* @var \Drupal\memcache\DrupalMemcacheFactory
* @var \Drupal\memcache\Driver\MemcacheDriverFactory
*/
protected $memcacheFactory;
......@@ -32,10 +33,10 @@ class MemcacheBackendFactory implements CacheFactoryInterface {
/**
* Constructs the DatabaseBackendFactory object.
*
* @param \Drupal\memcache\DrupalMemcacheFactory $memcache_factory
* @param \Drupal\memcache\Driver\MemcacheDriverFactory $memcache_factory
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
*/
function __construct(DrupalMemcacheFactory $memcache_factory, CacheTagsChecksumInterface $checksum_provider) {
function __construct(MemcacheDriverFactory $memcache_factory, CacheTagsChecksumInterface $checksum_provider) {
$this->memcacheFactory = $memcache_factory;
$this->checksumProvider = $checksum_provider;
}
......
<?php
/**
* @file
* Contains \Drupal\memcache\DrupalMemcacheConfig.
*/
namespace Drupal\memcache;
use Drupal\Core\Site\Settings;
......@@ -12,7 +7,7 @@ use Drupal\Core\Site\Settings;
/**
* Class for holding Memcache related config
*/
class DrupalMemcacheConfig {
class MemcacheSettings {
/**
* Array with the settings.
......
<?php
/**
* @file
* Contains \Drupal\memcache\Tests\DrupalMemcacheConfigTest.
*/
namespace Drupal\Tests\memcache\Unit;
use Drupal\memcache\DrupalMemcacheConfig;
use Drupal\memcache\MemcacheSettings;
use Drupal\Core\Site\Settings;
use Drupal\Tests\UnitTestCase;
/**
* @coversDefaultClass \Drupal\memcache\DrupalMemcacheConfig
* @coversDefaultClass \Drupal\memcache\MemcacheSettings
* @group memcache
*/
class DrupalMemcacheConfigTest extends UnitTestCase {
class MemcacheSettingsTest extends UnitTestCase {
/**
* Simple settings array to test against.
......@@ -27,7 +22,7 @@ class DrupalMemcacheConfigTest extends UnitTestCase {
/**
* The class under test.
*
* @var \Drupal\memcache\DrupalMemcacheConfig
* @var \Drupal\memcache\MemcacheSettings
*/
protected $settings;
......@@ -43,7 +38,7 @@ class DrupalMemcacheConfigTest extends UnitTestCase {
'hash_salt' => $this->randomMachineName(),
];
$settings = new Settings($this->config);
$this->settings = new DrupalMemcacheConfig($settings);
$this->settings = new MemcacheSettings($settings);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment