Issue #3113971 by Spokje, mondrake, acbramley, phenaproxima, andypost, murilohp, mpdonadio, ravi.shankar, pavnish, pifagor, vladbo, JeroenT, voleger, Taran2L: Replace REQUEST_TIME in services
parent
9231c9cf62
commit
fd75fa2134
|
@ -495,7 +495,7 @@
|
|||
"dist": {
|
||||
"type": "path",
|
||||
"url": "core",
|
||||
"reference": "cc2af7de02a19bfde449293a84468f5fb1e33cea"
|
||||
"reference": "52e04d4f59d5d77f898e4a3d2a63c1d809f139f7"
|
||||
},
|
||||
"require": {
|
||||
"asm89/stack-cors": "^2.1",
|
||||
|
@ -630,7 +630,8 @@
|
|||
"lib/Drupal/Core/DrupalKernel.php",
|
||||
"lib/Drupal/Core/DrupalKernelInterface.php",
|
||||
"lib/Drupal/Core/Installer/InstallerRedirectTrait.php",
|
||||
"lib/Drupal/Core/Site/Settings.php"
|
||||
"lib/Drupal/Core/Site/Settings.php",
|
||||
"lib/Drupal/Component/Datetime/Time.php"
|
||||
],
|
||||
"files": [
|
||||
"includes/bootstrap.inc"
|
||||
|
|
|
@ -105,7 +105,8 @@
|
|||
"lib/Drupal/Core/DrupalKernel.php",
|
||||
"lib/Drupal/Core/DrupalKernelInterface.php",
|
||||
"lib/Drupal/Core/Installer/InstallerRedirectTrait.php",
|
||||
"lib/Drupal/Core/Site/Settings.php"
|
||||
"lib/Drupal/Core/Site/Settings.php",
|
||||
"lib/Drupal/Component/Datetime/Time.php"
|
||||
],
|
||||
"files": [
|
||||
"includes/bootstrap.inc"
|
||||
|
|
|
@ -228,19 +228,21 @@ services:
|
|||
- [setContainer, ['@service_container']]
|
||||
cache.backend.database:
|
||||
class: Drupal\Core\Cache\DatabaseBackendFactory
|
||||
arguments: ['@database', '@cache_tags.invalidator.checksum', '@settings', '@serialization.phpserialize']
|
||||
arguments: ['@database', '@cache_tags.invalidator.checksum', '@settings', '@serialization.phpserialize', '@datetime.time']
|
||||
tags:
|
||||
- { name: backend_overridable }
|
||||
cache.backend.apcu:
|
||||
class: Drupal\Core\Cache\ApcuBackendFactory
|
||||
arguments: ['%app.root%', '%site.path%', '@cache_tags.invalidator.checksum']
|
||||
arguments: ['%app.root%', '%site.path%', '@cache_tags.invalidator.checksum', '@datetime.time']
|
||||
cache.backend.php:
|
||||
class: Drupal\Core\Cache\PhpBackendFactory
|
||||
arguments: ['@cache_tags.invalidator.checksum']
|
||||
arguments: ['@cache_tags.invalidator.checksum', '@datetime.time']
|
||||
cache.backend.memory:
|
||||
class: Drupal\Core\Cache\MemoryBackendFactory
|
||||
arguments: ['@datetime.time']
|
||||
cache.backend.memory.memory:
|
||||
class: Drupal\Core\Cache\MemoryCache\MemoryCacheFactory
|
||||
arguments: ['@datetime.time']
|
||||
# A special cache bin that does not persist beyond the length of the request.
|
||||
cache.static:
|
||||
class: Drupal\Core\Cache\CacheBackendInterface
|
||||
|
@ -490,7 +492,7 @@ services:
|
|||
arguments: ['@service_container', '%factory.keyvalue.expirable%']
|
||||
keyvalue.expirable.database:
|
||||
class: Drupal\Core\KeyValueStore\KeyValueDatabaseExpirableFactory
|
||||
arguments: ['@serialization.phpserialize', '@database']
|
||||
arguments: ['@serialization.phpserialize', '@database', '@datetime.time']
|
||||
logger.factory:
|
||||
class: Drupal\Core\Logger\LoggerChannelFactory
|
||||
parent: container.trait
|
||||
|
@ -686,6 +688,7 @@ services:
|
|||
Drupal\Core\Extension\ThemeInstallerInterface: '@theme_installer'
|
||||
entity.memory_cache:
|
||||
class: Drupal\Core\Cache\MemoryCache\MemoryCache
|
||||
arguments: ['@datetime.time']
|
||||
Drupal\Core\Cache\MemoryCache\MemoryCacheInterface: '@entity.memory_cache'
|
||||
entity_type.manager:
|
||||
class: Drupal\Core\Entity\EntityTypeManager
|
||||
|
@ -1377,7 +1380,7 @@ services:
|
|||
arguments: ['@html_response.attachments_processor']
|
||||
finish_response_subscriber:
|
||||
class: Drupal\Core\EventSubscriber\FinishResponseSubscriber
|
||||
arguments: ['@language_manager', '@config.factory', '@page_cache_request_policy', '@page_cache_response_policy', '@cache_contexts_manager', '%http.response.debug_cacheability_headers%']
|
||||
arguments: ['@language_manager', '@config.factory', '@page_cache_request_policy', '@page_cache_response_policy', '@cache_contexts_manager', '@datetime.time', '%http.response.debug_cacheability_headers%']
|
||||
response_generator_subscriber:
|
||||
class: Drupal\Core\EventSubscriber\ResponseGeneratorSubscriber
|
||||
redirect_response_subscriber:
|
||||
|
@ -1457,7 +1460,7 @@ services:
|
|||
arguments: [null, '@module_handler']
|
||||
flood:
|
||||
class: Drupal\Core\Flood\DatabaseBackend
|
||||
arguments: ['@database', '@request_stack']
|
||||
arguments: ['@database', '@request_stack', '@datetime.time']
|
||||
tags:
|
||||
- { name: backend_overridable }
|
||||
Drupal\Core\Flood\FloodInterface: '@flood'
|
||||
|
@ -1610,7 +1613,7 @@ services:
|
|||
alias: session_handler.storage
|
||||
session_handler.storage:
|
||||
class: Drupal\Core\Session\SessionHandler
|
||||
arguments: ['@request_stack', '@database']
|
||||
arguments: ['@request_stack', '@database', '@datetime.time']
|
||||
tags:
|
||||
- { name: backend_overridable }
|
||||
session_handler.write_safe:
|
||||
|
@ -1620,7 +1623,7 @@ services:
|
|||
Drupal\Core\Session\WriteSafeSessionHandlerInterface: '@session_handler.write_safe'
|
||||
session_manager:
|
||||
class: Drupal\Core\Session\SessionManager
|
||||
arguments: ['@request_stack', '@database', '@session_manager.metadata_bag', '@session_configuration', '@session_handler']
|
||||
arguments: ['@request_stack', '@database', '@session_manager.metadata_bag', '@session_configuration', '@datetime.time', '@session_handler']
|
||||
tags:
|
||||
- { name: backend_overridable }
|
||||
calls:
|
||||
|
@ -1646,7 +1649,7 @@ services:
|
|||
arguments: ['@file_system']
|
||||
asset.js.collection_renderer:
|
||||
class: Drupal\Core\Asset\JsCollectionRenderer
|
||||
arguments: [ '@asset.query_string','@file_url_generator' ]
|
||||
arguments: [ '@asset.query_string','@file_url_generator', '@datetime.time' ]
|
||||
asset.js.collection_optimizer:
|
||||
class: Drupal\Core\Asset\JsCollectionOptimizerLazy
|
||||
arguments: [ '@asset.js.collection_grouper', '@asset.js.optimizer', '@theme.manager', '@library.dependency_resolver', '@request_stack', '@file_system', '@config.factory', '@file_url_generator', '@datetime.time', '@language_manager']
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Asset;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Serialization\Json;
|
||||
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
|
||||
use Drupal\Core\File\FileUrlGeneratorInterface;
|
||||
|
@ -40,14 +41,24 @@ class JsCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
* The asset query string.
|
||||
* @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator
|
||||
* The file URL generator.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(AssetQueryStringInterface|StateInterface $asset_query_string, FileUrlGeneratorInterface $file_url_generator) {
|
||||
public function __construct(
|
||||
AssetQueryStringInterface|StateInterface $asset_query_string,
|
||||
FileUrlGeneratorInterface $file_url_generator,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
if ($asset_query_string instanceof StateInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() with the $asset_query_string argument as \Drupal\Core\State\StateInterface instead of \Drupal\Core\Asset\AssetQueryStringInterface is deprecated in drupal:10.2.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3358337', E_USER_DEPRECATED);
|
||||
$asset_query_string = \Drupal::service('asset.query_string');
|
||||
}
|
||||
$this->assetQueryString = $asset_query_string;
|
||||
$this->fileUrlGenerator = $file_url_generator;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +110,7 @@ class JsCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
// Only add the cache-busting query string if this isn't an aggregate
|
||||
// file.
|
||||
if (!isset($js_asset['preprocessed'])) {
|
||||
$element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : REQUEST_TIME);
|
||||
$element['#attributes']['src'] .= $query_string_separator . ($js_asset['cache'] ? $query_string : $this->time->getRequestTime());
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ class BatchStorage implements BatchStorageInterface {
|
|||
$this->session = $session;
|
||||
$this->csrfToken = $csrf_token;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3220378', E_USER_DEPRECATED);
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3220378', E_USER_DEPRECATED);
|
||||
$time = \Drupal::service('datetime.time');
|
||||
}
|
||||
$this->time = $time;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Assertion\Inspector;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
|
||||
/**
|
||||
* Stores cache items in the Alternative PHP Cache User Cache (APCu).
|
||||
|
@ -48,12 +49,23 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
* The prefix to use for all keys in the storage that belong to this site.
|
||||
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
|
||||
* The cache tags checksum provider.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct($bin, $site_prefix, CacheTagsChecksumInterface $checksum_provider) {
|
||||
public function __construct(
|
||||
$bin,
|
||||
$site_prefix,
|
||||
CacheTagsChecksumInterface $checksum_provider,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
$this->bin = $bin;
|
||||
$this->sitePrefix = $site_prefix;
|
||||
$this->checksumProvider = $checksum_provider;
|
||||
$this->binPrefix = $this->sitePrefix . '::' . $this->bin . '::';
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +157,7 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
$cache->tags = $cache->tags ? explode(' ', $cache->tags) : [];
|
||||
|
||||
// Check expire time.
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME;
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= $this->time->getRequestTime();
|
||||
|
||||
// Check if invalidateTags() has been called with any of the entry's tags.
|
||||
if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) {
|
||||
|
@ -235,7 +247,7 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
*/
|
||||
public function invalidateMultiple(array $cids) {
|
||||
foreach ($this->getMultiple($cids) as $cache) {
|
||||
$this->set($cache->cid, $cache, REQUEST_TIME - 1);
|
||||
$this->set($cache->cid, $cache, $this->time->getRequestTime() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,7 +257,7 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
public function invalidateAll() {
|
||||
foreach ($this->getAll() as $data) {
|
||||
$cid = str_replace($this->binPrefix, '', $data['key']);
|
||||
$this->set($cid, $data['value'], REQUEST_TIME - 1);
|
||||
$this->set($cid, $data['value'], $this->time->getRequestTime() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Site\Settings;
|
||||
|
||||
class ApcuBackendFactory implements CacheFactoryInterface {
|
||||
|
@ -36,11 +37,17 @@ class ApcuBackendFactory implements CacheFactoryInterface {
|
|||
* The site path.
|
||||
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
|
||||
* The cache tags checksum provider.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) {
|
||||
public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider, protected ?TimeInterface $time = NULL) {
|
||||
$this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path);
|
||||
$this->checksumProvider = $checksum_provider;
|
||||
$this->backendClass = 'Drupal\Core\Cache\ApcuBackend';
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +60,7 @@ class ApcuBackendFactory implements CacheFactoryInterface {
|
|||
* The cache backend object for the specified cache bin.
|
||||
*/
|
||||
public function get($bin) {
|
||||
return new $this->backendClass($bin, $this->sitePrefix, $this->checksumProvider);
|
||||
return new $this->backendClass($bin, $this->sitePrefix, $this->checksumProvider, $this->time);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Drupal\Core\Cache;
|
|||
|
||||
use Drupal\Component\Serialization\ObjectAwareSerializationInterface;
|
||||
use Drupal\Component\Assertion\Inspector;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\DatabaseException;
|
||||
|
@ -78,6 +79,8 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* The cache bin for which the object is created.
|
||||
* @param \Drupal\Component\Serialization\ObjectAwareSerializationInterface|int|string|null $serializer
|
||||
* (optional) The serializer to use.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|int|string|null $time
|
||||
* The time service.
|
||||
* @param int $max_rows
|
||||
* (optional) The maximum number of rows that are allowed in this cache bin
|
||||
* table.
|
||||
|
@ -87,6 +90,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
CacheTagsChecksumInterface $checksum_provider,
|
||||
$bin,
|
||||
protected ObjectAwareSerializationInterface|int|string|null $serializer = NULL,
|
||||
protected TimeInterface|int|string|null $time = NULL,
|
||||
$max_rows = NULL,
|
||||
) {
|
||||
// All cache tables should be prefixed with 'cache_'.
|
||||
|
@ -104,6 +108,13 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
@trigger_error('Calling ' . __METHOD__ . ' without the $serializer argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3014684', E_USER_DEPRECATED);
|
||||
$this->serializer = \Drupal::service('serialization.phpserialize');
|
||||
}
|
||||
if (!$this->time instanceof TimeInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be the 5th argument in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
if (is_int($time) || is_string($time)) {
|
||||
$max_rows = $time;
|
||||
}
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
$this->maxRows = $max_rows === NULL ? static::DEFAULT_MAX_ROWS : $max_rows;
|
||||
}
|
||||
|
||||
|
@ -174,7 +185,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
$cache->tags = $cache->tags ? explode(' ', $cache->tags) : [];
|
||||
|
||||
// Check expire time.
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME;
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= $this->time->getRequestTime();
|
||||
|
||||
// Check if invalidateTags() has been called with any of the item's tags.
|
||||
if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) {
|
||||
|
@ -363,9 +374,10 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
$cids = array_values(array_map([$this, 'normalizeCid'], $cids));
|
||||
try {
|
||||
// Update in chunks when a large array is passed.
|
||||
$requestTime = $this->time->getRequestTime();
|
||||
foreach (array_chunk($cids, 1000) as $cids_chunk) {
|
||||
$this->connection->update($this->bin)
|
||||
->fields(['expire' => REQUEST_TIME - 1])
|
||||
->fields(['expire' => $requestTime - 1])
|
||||
->condition('cid', $cids_chunk, 'IN')
|
||||
->execute();
|
||||
}
|
||||
|
@ -381,7 +393,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
public function invalidateAll() {
|
||||
try {
|
||||
$this->connection->update($this->bin)
|
||||
->fields(['expire' => REQUEST_TIME - 1])
|
||||
->fields(['expire' => $this->time->getRequestTime() - 1])
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
@ -412,7 +424,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
|
||||
$this->connection->delete($this->bin)
|
||||
->condition('expire', Cache::PERMANENT, '<>')
|
||||
->condition('expire', REQUEST_TIME, '<')
|
||||
->condition('expire', $this->time->getRequestTime(), '<')
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Serialization\ObjectAwareSerializationInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Site\Settings;
|
||||
|
@ -33,10 +34,18 @@ class DatabaseBackendFactory implements CacheFactoryInterface {
|
|||
* (optional) The site settings.
|
||||
* @param \Drupal\Component\Serialization\ObjectAwareSerializationInterface|null $serializer
|
||||
* (optional) The serializer to use.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*
|
||||
* @throws \BadMethodCallException
|
||||
*/
|
||||
public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider, protected ?Settings $settings = NULL, protected ?ObjectAwareSerializationInterface $serializer = NULL) {
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
CacheTagsChecksumInterface $checksum_provider,
|
||||
protected ?Settings $settings = NULL,
|
||||
protected ?ObjectAwareSerializationInterface $serializer = NULL,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->checksumProvider = $checksum_provider;
|
||||
if ($this->settings === NULL) {
|
||||
|
@ -47,6 +56,10 @@ class DatabaseBackendFactory implements CacheFactoryInterface {
|
|||
@trigger_error('Calling ' . __METHOD__ . ' without the $serializer argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3014684', E_USER_DEPRECATED);
|
||||
$this->serializer = \Drupal::service('serialization.phpserialize');
|
||||
}
|
||||
if ($this->time === NULL) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +73,7 @@ class DatabaseBackendFactory implements CacheFactoryInterface {
|
|||
*/
|
||||
public function get($bin) {
|
||||
$max_rows = $this->getMaxRowsForBin($bin);
|
||||
return new DatabaseBackend($this->connection, $this->checksumProvider, $bin, $this->serializer, $max_rows);
|
||||
return new DatabaseBackend($this->connection, $this->checksumProvider, $bin, $this->serializer, $this->time, $max_rows);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Assertion\Inspector;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
|
||||
/**
|
||||
* Defines a memory cache implementation.
|
||||
|
@ -26,6 +27,19 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
*/
|
||||
protected $cache = [];
|
||||
|
||||
/**
|
||||
* Constructs a MemoryBackend object.
|
||||
*
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(protected ?TimeInterface $time = NULL) {
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
@ -87,7 +101,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
$prepared->data = unserialize($prepared->data);
|
||||
|
||||
// Check expire time.
|
||||
$prepared->valid = $prepared->expire == Cache::PERMANENT || $prepared->expire >= $this->getRequestTime();
|
||||
$prepared->valid = $prepared->expire == Cache::PERMANENT || $prepared->expire >= $this->time->getRequestTime();
|
||||
|
||||
if (!$allow_invalid && !$prepared->valid) {
|
||||
return FALSE;
|
||||
|
@ -107,7 +121,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
$this->cache[$cid] = (object) [
|
||||
'cid' => $cid,
|
||||
'data' => serialize($data),
|
||||
'created' => $this->getRequestTime(),
|
||||
'created' => $this->time->getRequestTime(),
|
||||
'expire' => $expire,
|
||||
'tags' => $tags,
|
||||
];
|
||||
|
@ -148,7 +162,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
*/
|
||||
public function invalidate($cid) {
|
||||
if (isset($this->cache[$cid])) {
|
||||
$this->cache[$cid]->expire = $this->getRequestTime() - 1;
|
||||
$this->cache[$cid]->expire = $this->time->getRequestTime() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +172,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
public function invalidateMultiple(array $cids) {
|
||||
$items = array_intersect_key($this->cache, array_flip($cids));
|
||||
foreach ($items as $cid => $item) {
|
||||
$this->cache[$cid]->expire = $this->getRequestTime() - 1;
|
||||
$this->cache[$cid]->expire = $this->time->getRequestTime() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,7 +182,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
public function invalidateTags(array $tags) {
|
||||
foreach ($this->cache as $cid => $item) {
|
||||
if (array_intersect($tags, $item->tags)) {
|
||||
$this->cache[$cid]->expire = $this->getRequestTime() - 1;
|
||||
$this->cache[$cid]->expire = $this->time->getRequestTime() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -178,7 +192,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
*/
|
||||
public function invalidateAll() {
|
||||
foreach ($this->cache as $cid => $item) {
|
||||
$this->cache[$cid]->expire = $this->getRequestTime() - 1;
|
||||
$this->cache[$cid]->expire = $this->time->getRequestTime() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -201,14 +215,15 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
* @return int
|
||||
*/
|
||||
protected function getRequestTime() {
|
||||
return defined('REQUEST_TIME') ? REQUEST_TIME : (int) $_SERVER['REQUEST_TIME'];
|
||||
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 will be removed in drupal:11.0.0. Use the datetime.time service instead. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
return $this->time->getRequestTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents data stored in memory backends from being serialized.
|
||||
*/
|
||||
public function __sleep() {
|
||||
return [];
|
||||
return ['time'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
|
||||
class MemoryBackendFactory implements CacheFactoryInterface {
|
||||
|
||||
/**
|
||||
|
@ -11,12 +13,25 @@ class MemoryBackendFactory implements CacheFactoryInterface {
|
|||
*/
|
||||
protected $bins = [];
|
||||
|
||||
/**
|
||||
* Constructs a MemoryBackendFactory object.
|
||||
*
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(protected ?TimeInterface $time = NULL) {
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($bin) {
|
||||
if (!isset($this->bins[$bin])) {
|
||||
$this->bins[$bin] = new MemoryBackend();
|
||||
$this->bins[$bin] = new MemoryBackend($this->time);
|
||||
}
|
||||
return $this->bins[$bin];
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ class MemoryCache extends MemoryBackend implements MemoryCacheInterface {
|
|||
return FALSE;
|
||||
}
|
||||
// Check expire time.
|
||||
$cache->valid = $cache->expire == static::CACHE_PERMANENT || $cache->expire >= $this->getRequestTime();
|
||||
$cache->valid = $cache->expire == static::CACHE_PERMANENT || $cache->expire >= $this->time->getRequestTime();
|
||||
|
||||
if (!$allow_invalid && !$cache->valid) {
|
||||
return FALSE;
|
||||
|
@ -54,7 +54,7 @@ class MemoryCache extends MemoryBackend implements MemoryCacheInterface {
|
|||
$this->cache[$cid] = (object) [
|
||||
'cid' => $cid,
|
||||
'data' => $data,
|
||||
'created' => $this->getRequestTime(),
|
||||
'created' => $this->time->getRequestTime(),
|
||||
'expire' => $expire,
|
||||
'tags' => $tags,
|
||||
];
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Cache\MemoryCache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\CacheFactoryInterface;
|
||||
|
||||
class MemoryCacheFactory implements CacheFactoryInterface {
|
||||
|
@ -13,12 +14,25 @@ class MemoryCacheFactory implements CacheFactoryInterface {
|
|||
*/
|
||||
protected $bins = [];
|
||||
|
||||
/**
|
||||
* Constructs a MemoryCounterBackendFactory object.
|
||||
*
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(protected ?TimeInterface $time = NULL) {
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($bin) {
|
||||
if (!isset($this->bins[$bin])) {
|
||||
$this->bins[$bin] = new MemoryCache();
|
||||
$this->bins[$bin] = new MemoryCache($this->time);
|
||||
}
|
||||
return $this->bins[$bin];
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
|
||||
class MemoryCounterBackendFactory implements CacheFactoryInterface {
|
||||
|
||||
/**
|
||||
|
@ -11,12 +13,25 @@ class MemoryCounterBackendFactory implements CacheFactoryInterface {
|
|||
*/
|
||||
protected $bins = [];
|
||||
|
||||
/**
|
||||
* Constructs a MemoryCounterBackendFactory object.
|
||||
*
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(protected ?TimeInterface $time = NULL) {
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($bin) {
|
||||
if (!isset($this->bins[$bin])) {
|
||||
$this->bins[$bin] = new MemoryCounterBackend();
|
||||
$this->bins[$bin] = new MemoryCounterBackend($this->time);
|
||||
}
|
||||
return $this->bins[$bin];
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Assertion\Inspector;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\PhpStorage\PhpStorageInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\PhpStorage\PhpStorageFactory;
|
||||
|
@ -51,10 +52,16 @@ class PhpBackend implements CacheBackendInterface {
|
|||
* The cache bin for which the object is created.
|
||||
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
|
||||
* The cache tags checksum provider.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct($bin, CacheTagsChecksumInterface $checksum_provider) {
|
||||
public function __construct($bin, CacheTagsChecksumInterface $checksum_provider, protected ?TimeInterface $time = NULL) {
|
||||
$this->bin = 'cache_' . $bin;
|
||||
$this->checksumProvider = $checksum_provider;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -132,7 +139,7 @@ class PhpBackend implements CacheBackendInterface {
|
|||
}
|
||||
|
||||
// Check expire time.
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME;
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= $this->time->getRequestTime();
|
||||
|
||||
// Check if invalidateTags() has been called with any of the item's tags.
|
||||
if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) {
|
||||
|
@ -201,7 +208,7 @@ class PhpBackend implements CacheBackendInterface {
|
|||
*/
|
||||
protected function invalidateByHash($cidhash) {
|
||||
if ($item = $this->getByHash($cidhash)) {
|
||||
$item->expire = REQUEST_TIME - 1;
|
||||
$item->expire = $this->time->getRequestTime() - 1;
|
||||
$this->writeItem($cidhash, $item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
|
||||
class PhpBackendFactory implements CacheFactoryInterface {
|
||||
|
||||
/**
|
||||
|
@ -16,9 +18,15 @@ class PhpBackendFactory implements CacheFactoryInterface {
|
|||
*
|
||||
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
|
||||
* The cache tags checksum provider.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(CacheTagsChecksumInterface $checksum_provider) {
|
||||
public function __construct(CacheTagsChecksumInterface $checksum_provider, protected ?TimeInterface $time = NULL) {
|
||||
$this->checksumProvider = $checksum_provider;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +39,7 @@ class PhpBackendFactory implements CacheFactoryInterface {
|
|||
* The cache backend object for the specified cache bin.
|
||||
*/
|
||||
public function get($bin) {
|
||||
return new PhpBackend($bin, $this->checksumProvider);
|
||||
return new PhpBackend($bin, $this->checksumProvider, $this->time);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Drupal\Core\Config;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
use Drupal\Core\Cache\NullBackend;
|
||||
use Drupal\Core\Config\Entity\ConfigDependencyManager;
|
||||
|
@ -112,6 +114,7 @@ class StorageComparer implements StorageComparerInterface {
|
|||
$target_storage = $target_storage->createCollection(StorageInterface::DEFAULT_COLLECTION);
|
||||
}
|
||||
|
||||
$time = \Drupal::hasService(TimeInterface::class) ? \Drupal::service(TimeInterface::class) : new Time();
|
||||
if ($source_storage instanceof FileStorage) {
|
||||
// FileStorage has its own static cache so that multiple reads of the
|
||||
// same raw configuration object are not costly.
|
||||
|
@ -121,14 +124,14 @@ class StorageComparer implements StorageComparerInterface {
|
|||
else {
|
||||
// Wrap the source storage in a static cache so that multiple reads of the
|
||||
// same raw configuration object are not costly.
|
||||
$this->sourceCacheStorage = new MemoryBackend();
|
||||
$this->sourceCacheStorage = new MemoryBackend($time);
|
||||
$this->sourceStorage = new CachedStorage(
|
||||
$source_storage,
|
||||
$this->sourceCacheStorage
|
||||
);
|
||||
}
|
||||
|
||||
$this->targetCacheStorage = new MemoryBackend();
|
||||
$this->targetCacheStorage = new MemoryBackend($time);
|
||||
$this->targetStorage = $target_storage;
|
||||
$this->changelist[StorageInterface::DEFAULT_COLLECTION] = $this->getEmptyChangelist();
|
||||
}
|
||||
|
|
|
@ -75,6 +75,13 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
'factory' => 'Drupal\Core\Database\Database::getConnection',
|
||||
'arguments' => ['default'],
|
||||
],
|
||||
'request_stack' => [
|
||||
'class' => 'Symfony\Component\HttpFoundation\RequestStack',
|
||||
],
|
||||
'datetime.time' => [
|
||||
'class' => 'Drupal\Component\Datetime\Time',
|
||||
'arguments' => ['@request_stack'],
|
||||
],
|
||||
'cache.container' => [
|
||||
'class' => 'Drupal\Core\Cache\DatabaseBackend',
|
||||
'arguments' => [
|
||||
|
@ -82,6 +89,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
|
|||
'@cache_tags_provider.container',
|
||||
'container',
|
||||
'@serialization.phpserialize',
|
||||
'@datetime.time',
|
||||
DatabaseBackend::MAXIMUM_NONE,
|
||||
],
|
||||
],
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Component\Datetime\DateTimePlus;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\CacheableResponseInterface;
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
|
@ -74,15 +75,32 @@ class FinishResponseSubscriber implements EventSubscriberInterface {
|
|||
* A policy rule determining the cacheability of a response.
|
||||
* @param \Drupal\Core\Cache\Context\CacheContextsManager $cache_contexts_manager
|
||||
* The cache contexts manager service.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null|bool $time
|
||||
* The time service.
|
||||
* @param bool $http_response_debug_cacheability_headers
|
||||
* (optional) Whether to send cacheability headers for debugging purposes.
|
||||
*/
|
||||
public function __construct(LanguageManagerInterface $language_manager, ConfigFactoryInterface $config_factory, RequestPolicyInterface $request_policy, ResponsePolicyInterface $response_policy, CacheContextsManager $cache_contexts_manager, $http_response_debug_cacheability_headers = FALSE) {
|
||||
public function __construct(
|
||||
LanguageManagerInterface $language_manager,
|
||||
ConfigFactoryInterface $config_factory,
|
||||
RequestPolicyInterface $request_policy,
|
||||
ResponsePolicyInterface $response_policy,
|
||||
CacheContextsManager $cache_contexts_manager,
|
||||
protected TimeInterface|bool|null $time = NULL,
|
||||
$http_response_debug_cacheability_headers = FALSE,
|
||||
) {
|
||||
$this->languageManager = $language_manager;
|
||||
$this->config = $config_factory->get('system.performance');
|
||||
$this->requestPolicy = $request_policy;
|
||||
$this->responsePolicy = $response_policy;
|
||||
$this->cacheContextsManager = $cache_contexts_manager;
|
||||
if (!$time || is_bool($time)) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be the 5th argument in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
if (is_bool($time)) {
|
||||
$http_response_debug_cacheability_headers = $time;
|
||||
}
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
$this->debugCacheabilityHeaders = $http_response_debug_cacheability_headers;
|
||||
}
|
||||
|
||||
|
@ -257,8 +275,8 @@ class FinishResponseSubscriber implements EventSubscriberInterface {
|
|||
// In order to support HTTP cache-revalidation, ensure that there is a
|
||||
// Last-Modified and an ETag header on the response.
|
||||
if (!$response->headers->has('Last-Modified')) {
|
||||
$timestamp = REQUEST_TIME;
|
||||
$response->setLastModified(new \DateTime(gmdate(DateTimePlus::RFC7231, REQUEST_TIME)));
|
||||
$timestamp = $this->time->getRequestTime();
|
||||
$response->setLastModified(new \DateTime(gmdate(DateTimePlus::RFC7231, $this->time->getRequestTime())));
|
||||
}
|
||||
else {
|
||||
$timestamp = $response->getLastModified()->getTimestamp();
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
|
||||
namespace Drupal\Core\Flood;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\DatabaseException;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Drupal\Core\Database\Connection;
|
||||
|
||||
/**
|
||||
* Defines the database flood backend. This is the default Drupal backend.
|
||||
|
@ -38,10 +39,16 @@ class DatabaseBackend implements FloodInterface, PrefixFloodInterface {
|
|||
* information.
|
||||
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
|
||||
* The request stack used to retrieve the current request.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(Connection $connection, RequestStack $request_stack) {
|
||||
public function __construct(Connection $connection, RequestStack $request_stack, protected ?TimeInterface $time = NULL) {
|
||||
$this->connection = $connection;
|
||||
$this->requestStack = $request_stack;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,8 +90,8 @@ class DatabaseBackend implements FloodInterface, PrefixFloodInterface {
|
|||
->fields([
|
||||
'event' => $name,
|
||||
'identifier' => $identifier,
|
||||
'timestamp' => REQUEST_TIME,
|
||||
'expiration' => REQUEST_TIME + $window,
|
||||
'timestamp' => $this->time->getRequestTime(),
|
||||
'expiration' => $this->time->getRequestTime() + $window,
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
|
@ -133,7 +140,7 @@ class DatabaseBackend implements FloodInterface, PrefixFloodInterface {
|
|||
$number = $this->connection->select(static::TABLE_NAME, 'f')
|
||||
->condition('event', $name)
|
||||
->condition('identifier', $identifier)
|
||||
->condition('timestamp', REQUEST_TIME - $window, '>')
|
||||
->condition('timestamp', $this->time->getRequestTime() - $window, '>')
|
||||
->countQuery()
|
||||
->execute()
|
||||
->fetchField();
|
||||
|
@ -153,7 +160,7 @@ class DatabaseBackend implements FloodInterface, PrefixFloodInterface {
|
|||
public function garbageCollection() {
|
||||
try {
|
||||
$this->connection->delete(static::TABLE_NAME)
|
||||
->condition('expiration', REQUEST_TIME, '<')
|
||||
->condition('expiration', $this->time->getRequestTime(), '<')
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Installer;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\MemoryBackendFactory;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\DependencyInjection\ServiceProviderInterface;
|
||||
|
@ -37,7 +38,7 @@ class NormalInstallerServiceProvider implements ServiceProviderInterface {
|
|||
// install.
|
||||
$definition = $container->getDefinition('cache_factory');
|
||||
$definition->setClass(MemoryBackendFactory::class);
|
||||
$definition->setArguments([]);
|
||||
$definition->setArguments([new Time()]);
|
||||
$definition->setMethodCalls([]);
|
||||
|
||||
// Replace lock service with no-op implementation as Drupal installation can
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\KeyValueStore;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Serialization\SerializationInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
|
||||
|
@ -38,10 +39,20 @@ class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterf
|
|||
* The serialization class to use.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The Connection object containing the key-value tables.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(SerializationInterface $serializer, Connection $connection) {
|
||||
public function __construct(
|
||||
SerializationInterface $serializer,
|
||||
Connection $connection,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
$this->serializer = $serializer;
|
||||
$this->connection = $connection;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +71,7 @@ class KeyValueDatabaseExpirableFactory implements KeyValueExpirableFactoryInterf
|
|||
public function garbageCollection() {
|
||||
try {
|
||||
$this->connection->delete('key_value_expire')
|
||||
->condition('expire', REQUEST_TIME, '<')
|
||||
->condition('expire', $this->time->getRequestTime(), '<')
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Session;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
|
@ -36,10 +37,16 @@ class SessionHandler extends AbstractProxy implements \SessionHandlerInterface {
|
|||
* The request stack.
|
||||
* @param \Drupal\Core\Database\Connection $connection
|
||||
* The database connection.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(RequestStack $request_stack, Connection $connection) {
|
||||
public function __construct(RequestStack $request_stack, Connection $connection, protected ?TimeInterface $time = NULL) {
|
||||
$this->requestStack = $request_stack;
|
||||
$this->connection = $connection;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +79,7 @@ class SessionHandler extends AbstractProxy implements \SessionHandlerInterface {
|
|||
'uid' => $request->getSession()->get('uid', 0),
|
||||
'hostname' => $request->getClientIP(),
|
||||
'session' => $value,
|
||||
'timestamp' => REQUEST_TIME,
|
||||
'timestamp' => $this->time->getRequestTime(),
|
||||
];
|
||||
$this->connection->merge('sessions')
|
||||
->keys(['sid' => Crypt::hashBase64($sid)])
|
||||
|
@ -110,7 +117,7 @@ class SessionHandler extends AbstractProxy implements \SessionHandlerInterface {
|
|||
// to '1814400'. At that value, only after a user doesn't log in after
|
||||
// three weeks (1814400 seconds) will their session be removed.
|
||||
return $this->connection->delete('sessions')
|
||||
->condition('timestamp', REQUEST_TIME - $lifetime, '<')
|
||||
->condition('timestamp', $this->time->getRequestTime() - $lifetime, '<')
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
namespace Drupal\Core\Session;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
|
||||
|
||||
/**
|
||||
* Manages user sessions.
|
||||
|
@ -77,15 +79,32 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
|||
* The session metadata bag.
|
||||
* @param \Drupal\Core\Session\SessionConfigurationInterface $session_configuration
|
||||
* The session configuration interface.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null|\Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy|\SessionHandlerInterface $time
|
||||
* The time service.
|
||||
* @param \Symfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy|\SessionHandlerInterface|null $handler
|
||||
* The object to register as a PHP session handler.
|
||||
* @see \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::setSaveHandler()
|
||||
*
|
||||
* @see \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::setSaveHandler()
|
||||
*/
|
||||
public function __construct(RequestStack $request_stack, Connection $connection, MetadataBag $metadata_bag, SessionConfigurationInterface $session_configuration, $handler = NULL) {
|
||||
public function __construct(
|
||||
RequestStack $request_stack,
|
||||
Connection $connection,
|
||||
MetadataBag $metadata_bag,
|
||||
SessionConfigurationInterface $session_configuration,
|
||||
protected TimeInterface|AbstractProxy|\SessionHandlerInterface|null $time = NULL,
|
||||
$handler = NULL,
|
||||
) {
|
||||
$options = [];
|
||||
$this->sessionConfiguration = $session_configuration;
|
||||
$this->requestStack = $request_stack;
|
||||
$this->connection = $connection;
|
||||
if (!$time || $time instanceof AbstractProxy || $time instanceof \SessionHandlerInterface) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be the 5th argument in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
if ($time instanceof AbstractProxy || $time instanceof \SessionHandlerInterface) {
|
||||
$handler = $time;
|
||||
}
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
|
||||
parent::__construct($options, $handler, $metadata_bag);
|
||||
}
|
||||
|
@ -242,7 +261,7 @@ class SessionManager extends NativeSessionStorage implements SessionManagerInter
|
|||
// setcookie() can only be called when headers are not yet sent.
|
||||
if ($cookies->has($session_name) && !headers_sent()) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie($session_name, '', REQUEST_TIME - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
|
||||
setcookie($session_name, '', $this->time->getRequestTime() - 3600, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
|
||||
$cookies->remove($session_name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,9 @@ services:
|
|||
Drupal\comment\CommentManagerInterface: '@comment.manager'
|
||||
|
||||
comment.statistics:
|
||||
autowire: true
|
||||
class: Drupal\comment\CommentStatistics
|
||||
arguments: ['@database', '@current_user', '@entity_type.manager', '@state', '@database.replica']
|
||||
arguments: ['@database', '@current_user', '@entity_type.manager', '@state', '@datetime.time', '@database.replica']
|
||||
tags:
|
||||
- { name: backend_overridable }
|
||||
Drupal\comment\CommentStatisticsInterface: '@comment.statistics'
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\comment;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
|
@ -59,15 +60,31 @@ class CommentStatistics implements CommentStatisticsInterface {
|
|||
* The entity type manager.
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
* The state service.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null|\Drupal\Core\Database\Connection $time
|
||||
* The time service.
|
||||
* @param \Drupal\Core\Database\Connection|null $database_replica
|
||||
* (Optional) the replica database connection.
|
||||
*/
|
||||
public function __construct(Connection $database, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, StateInterface $state, Connection $database_replica = NULL) {
|
||||
public function __construct(
|
||||
Connection $database,
|
||||
AccountInterface $current_user,
|
||||
EntityTypeManagerInterface $entity_type_manager,
|
||||
StateInterface $state,
|
||||
protected TimeInterface|Connection|null $time = NULL,
|
||||
Connection $database_replica = NULL,
|
||||
) {
|
||||
$this->database = $database;
|
||||
$this->databaseReplica = $database_replica ?: $database;
|
||||
$this->currentUser = $current_user;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->state = $state;
|
||||
if (!$time || $time instanceof Connection) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be the 4th argument in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
if ($time instanceof Connection) {
|
||||
$database_replica = $time;
|
||||
}
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
$this->databaseReplica = $database_replica ?: $database;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,8 +146,8 @@ class CommentStatistics implements CommentStatisticsInterface {
|
|||
// EntityOwnerInterface or author is not set.
|
||||
$last_comment_uid = $this->currentUser->id();
|
||||
}
|
||||
// Default to REQUEST_TIME when entity does not have a changed property.
|
||||
$last_comment_timestamp = REQUEST_TIME;
|
||||
// Default to request time when entity does not have a changed property.
|
||||
$last_comment_timestamp = $this->time->getRequestTime();
|
||||
// @todo Make comment statistics language aware and add some tests. See
|
||||
// https://www.drupal.org/node/2318875
|
||||
if ($entity instanceof EntityChangedInterface) {
|
||||
|
@ -251,8 +268,8 @@ class CommentStatistics implements CommentStatisticsInterface {
|
|||
'cid' => 0,
|
||||
'comment_count' => 0,
|
||||
// Use the changed date of the entity if it's set, or default to
|
||||
// REQUEST_TIME.
|
||||
'last_comment_timestamp' => ($entity instanceof EntityChangedInterface) ? $entity->getChangedTimeAcrossTranslations() : REQUEST_TIME,
|
||||
// request time.
|
||||
'last_comment_timestamp' => ($entity instanceof EntityChangedInterface) ? $entity->getChangedTimeAcrossTranslations() : $this->time->getRequestTime(),
|
||||
'last_comment_name' => '',
|
||||
'last_comment_uid' => $last_comment_uid,
|
||||
])
|
||||
|
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Drupal\Tests\comment\Unit;
|
||||
|
||||
use Drupal\comment\CommentStatistics;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
|
@ -87,7 +88,7 @@ class CommentStatisticsUnitTest extends UnitTestCase {
|
|||
->method('select')
|
||||
->willReturn($this->select);
|
||||
|
||||
$this->commentStatistics = new CommentStatistics($this->database, $this->createMock('Drupal\Core\Session\AccountInterface'), $this->createMock(EntityTypeManagerInterface::class), $this->createMock('Drupal\Core\State\StateInterface'), $this->database);
|
||||
$this->commentStatistics = new CommentStatistics($this->database, $this->createMock('Drupal\Core\Session\AccountInterface'), $this->createMock(EntityTypeManagerInterface::class), $this->createMock('Drupal\Core\State\StateInterface'), $this->createMock(TimeInterface::class), $this->database);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Drupal\Tests\migrate\Kernel;
|
|||
use Drupal\Core\Cache\MemoryCounterBackendFactory;
|
||||
use Drupal\sqlite\Driver\Database\sqlite\Connection;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Base class for tests of Migrate source plugins that use a database.
|
||||
|
@ -16,7 +17,9 @@ abstract class MigrateSqlSourceTestBase extends MigrateSourceTestBase {
|
|||
*/
|
||||
public function register(ContainerBuilder $container) {
|
||||
parent::register($container);
|
||||
$container->register('cache_factory', MemoryCounterBackendFactory::class);
|
||||
$container
|
||||
->register('cache_factory', MemoryCounterBackendFactory::class)
|
||||
->addArgument(new Reference('datetime.time'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\mysql\Kernel\mysql;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Command\DbDumpApplication;
|
||||
use Drupal\Core\Config\DatabaseStorage;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
@ -75,7 +76,8 @@ class DbDumpTest extends DriverSpecificKernelTestBase {
|
|||
->addArgument(new Reference('database'))
|
||||
->addArgument(new Reference('cache_tags.invalidator.checksum'))
|
||||
->addArgument(new Reference('settings'))
|
||||
->addArgument(new Reference('serialization.phpserialize'));
|
||||
->addArgument(new Reference('serialization.phpserialize'))
|
||||
->addArgument(new Reference(TimeInterface::class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@ services:
|
|||
arguments: ['@path_alias.manager']
|
||||
path_alias.manager:
|
||||
class: Drupal\path_alias\AliasManager
|
||||
arguments: ['@path_alias.repository', '@path_alias.whitelist', '@language_manager', '@cache.data']
|
||||
arguments: ['@path_alias.repository', '@path_alias.whitelist', '@language_manager', '@cache.data', '@datetime.time']
|
||||
Drupal\path_alias\AliasManagerInterface: '@path_alias.manager'
|
||||
path_alias.repository:
|
||||
class: Drupal\path_alias\AliasRepository
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\path_alias;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
|
@ -102,12 +103,24 @@ class AliasManager implements AliasManagerInterface {
|
|||
* The language manager.
|
||||
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
|
||||
* Cache backend.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(AliasRepositoryInterface $alias_repository, AliasWhitelistInterface $whitelist, LanguageManagerInterface $language_manager, CacheBackendInterface $cache) {
|
||||
public function __construct(
|
||||
AliasRepositoryInterface $alias_repository,
|
||||
AliasWhitelistInterface $whitelist,
|
||||
LanguageManagerInterface $language_manager,
|
||||
CacheBackendInterface $cache,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
$this->pathAliasRepository = $alias_repository;
|
||||
$this->languageManager = $language_manager;
|
||||
$this->whitelist = $whitelist;
|
||||
$this->cache = $cache;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,7 +153,7 @@ class AliasManager implements AliasManagerInterface {
|
|||
}
|
||||
|
||||
$twenty_four_hours = 60 * 60 * 24;
|
||||
$this->cache->set($this->cacheKey, $path_lookups, $this->getRequestTime() + $twenty_four_hours);
|
||||
$this->cache->set($this->cacheKey, $path_lookups, $this->time->getRequestTime() + $twenty_four_hours);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,9 +304,15 @@ class AliasManager implements AliasManagerInterface {
|
|||
* Wrapper method for REQUEST_TIME constant.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
|
||||
* the $this->time->getRequestTime() service instead.
|
||||
*
|
||||
* @see https://www.drupal.org/node/3387233
|
||||
*/
|
||||
protected function getRequestTime() {
|
||||
return defined('REQUEST_TIME') ? REQUEST_TIME : (int) $_SERVER['REQUEST_TIME'];
|
||||
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use the $this->time->getRequestTime() instead. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
return $this->time->getRequestTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\path_alias\Kernel;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\MemoryCounterBackend;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
@ -358,11 +359,11 @@ class AliasTest extends KernelTestBase {
|
|||
* Tests the alias whitelist.
|
||||
*/
|
||||
public function testWhitelist() {
|
||||
$memoryCounterBackend = new MemoryCounterBackend();
|
||||
$memoryCounterBackend = new MemoryCounterBackend(\Drupal::service(TimeInterface::class));
|
||||
|
||||
// Create AliasManager and Path object.
|
||||
$whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $this->container->get('path_alias.repository'));
|
||||
$aliasManager = new AliasManager($this->container->get('path_alias.repository'), $whitelist, $this->container->get('language_manager'), $memoryCounterBackend);
|
||||
$aliasManager = new AliasManager($this->container->get('path_alias.repository'), $whitelist, $this->container->get('language_manager'), $memoryCounterBackend, $this->container->get(TimeInterface::class));
|
||||
|
||||
// No alias for user and admin yet, so should be NULL.
|
||||
$this->assertNull($whitelist->get('user'));
|
||||
|
@ -419,7 +420,7 @@ class AliasTest extends KernelTestBase {
|
|||
* Tests situation where the whitelist cache is deleted mid-request.
|
||||
*/
|
||||
public function testWhitelistCacheDeletionMidRequest() {
|
||||
$memoryCounterBackend = new MemoryCounterBackend();
|
||||
$memoryCounterBackend = new MemoryCounterBackend(\Drupal::service(TimeInterface::class));
|
||||
|
||||
// Create AliasManager and Path object.
|
||||
$whitelist = new AliasWhitelist('path_alias_whitelist', $memoryCounterBackend, $this->container->get('lock'), $this->container->get('state'), $this->container->get('path_alias.repository'));
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\path_alias\Unit;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\path_alias\AliasRepositoryInterface;
|
||||
|
@ -76,7 +77,7 @@ class AliasManagerTest extends UnitTestCase {
|
|||
$this->languageManager = $this->createMock('Drupal\Core\Language\LanguageManagerInterface');
|
||||
$this->cache = $this->createMock('Drupal\Core\Cache\CacheBackendInterface');
|
||||
|
||||
$this->aliasManager = new AliasManager($this->aliasRepository, $this->aliasWhitelist, $this->languageManager, $this->cache);
|
||||
$this->aliasManager = new AliasManager($this->aliasRepository, $this->aliasWhitelist, $this->languageManager, $this->cache, new Time());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ services:
|
|||
|
||||
search.index:
|
||||
class: Drupal\search\SearchIndex
|
||||
arguments: ['@config.factory', '@database','@database.replica', '@cache_tags.invalidator', '@search.text_processor']
|
||||
arguments: ['@config.factory', '@database','@database.replica', '@cache_tags.invalidator', '@search.text_processor', '@datetime.time']
|
||||
tags:
|
||||
- { name: backend_overridable }
|
||||
Drupal\search\SearchIndexInterface: '@search.index'
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\search;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Database\Connection;
|
||||
|
@ -60,13 +61,26 @@ class SearchIndex implements SearchIndexInterface {
|
|||
* The cache tags invalidator.
|
||||
* @param \Drupal\search\SearchTextProcessorInterface $text_processor
|
||||
* The text processor.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory, Connection $connection, Connection $replica, CacheTagsInvalidatorInterface $cache_tags_invalidator, SearchTextProcessorInterface $text_processor) {
|
||||
public function __construct(
|
||||
ConfigFactoryInterface $config_factory,
|
||||
Connection $connection,
|
||||
Connection $replica,
|
||||
CacheTagsInvalidatorInterface $cache_tags_invalidator,
|
||||
SearchTextProcessorInterface $text_processor,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
$this->configFactory = $config_factory;
|
||||
$this->connection = $connection;
|
||||
$this->replica = $replica;
|
||||
$this->cacheTagsInvalidator = $cache_tags_invalidator;
|
||||
$this->textProcessor = $text_processor;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -265,7 +279,7 @@ class SearchIndex implements SearchIndexInterface {
|
|||
|
||||
try {
|
||||
$query = $this->connection->update('search_dataset')
|
||||
->fields(['reindex' => REQUEST_TIME])
|
||||
->fields(['reindex' => $this->time->getRequestTime()])
|
||||
// Only mark items that were not previously marked for reindex, so that
|
||||
// marked items maintain their priority by request time.
|
||||
->condition('reindex', 0);
|
||||
|
|
|
@ -82,6 +82,7 @@ services:
|
|||
arguments: ['@menu.link_tree', '@system.module_admin_links_memory_cache']
|
||||
system.module_admin_links_memory_cache:
|
||||
class: Drupal\Core\Cache\MemoryCache\MemoryCache
|
||||
arguments: ['@datetime.time']
|
||||
system.access_route_alter_subscriber:
|
||||
class: Drupal\system\EventSubscriber\AccessRouteAlterSubscriber
|
||||
tags:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Tests\system\Kernel\System;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Flood\DatabaseBackend;
|
||||
use Drupal\Core\Flood\MemoryBackend;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
|
@ -56,7 +57,8 @@ class FloodTest extends KernelTestBase {
|
|||
|
||||
$connection = \Drupal::service('database');
|
||||
$request_stack = \Drupal::service('request_stack');
|
||||
$flood = new DatabaseBackend($connection, $request_stack);
|
||||
$time = \Drupal::service(TimeInterface::class);
|
||||
$flood = new DatabaseBackend($connection, $request_stack, $time);
|
||||
$this->assertTrue($flood->isAllowed($name, $threshold));
|
||||
// Register expired event.
|
||||
$flood->register($name, $window_expired);
|
||||
|
@ -81,10 +83,11 @@ class FloodTest extends KernelTestBase {
|
|||
public function floodBackendProvider() :array {
|
||||
$request_stack = \Drupal::service('request_stack');
|
||||
$connection = \Drupal::service('database');
|
||||
$time = \Drupal::service(TimeInterface::class);
|
||||
|
||||
return [
|
||||
new MemoryBackend($request_stack),
|
||||
new DatabaseBackend($connection, $request_stack),
|
||||
new DatabaseBackend($connection, $request_stack, $time),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\update;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
|
||||
|
@ -100,8 +101,19 @@ class UpdateProcessor implements UpdateProcessorInterface {
|
|||
* The key/value factory.
|
||||
* @param \Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface $key_value_expirable_factory
|
||||
* The expirable key/value factory.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory, QueueFactory $queue_factory, UpdateFetcherInterface $update_fetcher, StateInterface $state_store, PrivateKey $private_key, KeyValueFactoryInterface $key_value_factory, KeyValueExpirableFactoryInterface $key_value_expirable_factory) {
|
||||
public function __construct(
|
||||
ConfigFactoryInterface $config_factory,
|
||||
QueueFactory $queue_factory,
|
||||
UpdateFetcherInterface $update_fetcher,
|
||||
StateInterface $state_store,
|
||||
PrivateKey $private_key,
|
||||
KeyValueFactoryInterface $key_value_factory,
|
||||
KeyValueExpirableFactoryInterface $key_value_expirable_factory,
|
||||
protected ?TimeInterface $time = NULL,
|
||||
) {
|
||||
$this->updateFetcher = $update_fetcher;
|
||||
$this->updateSettings = $config_factory->get('update.settings');
|
||||
$this->fetchQueue = $queue_factory->get('update_fetch_tasks');
|
||||
|
@ -110,6 +122,10 @@ class UpdateProcessor implements UpdateProcessorInterface {
|
|||
$this->availableReleasesTempStore = $key_value_expirable_factory->get('update_available_releases');
|
||||
$this->stateStore = $state_store;
|
||||
$this->privateKey = $private_key;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
$this->fetchTasks = [];
|
||||
$this->failed = [];
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ services:
|
|||
Drupal\update\UpdateManagerInterface: '@update.manager'
|
||||
update.processor:
|
||||
class: Drupal\update\UpdateProcessor
|
||||
arguments: ['@config.factory', '@queue', '@update.fetcher', '@state', '@private_key', '@keyvalue', '@keyvalue.expirable']
|
||||
arguments: ['@config.factory', '@queue', '@update.fetcher', '@state', '@private_key', '@keyvalue', '@keyvalue.expirable', '@datetime.time']
|
||||
Drupal\update\UpdateProcessorInterface: '@update.processor'
|
||||
update.fetcher:
|
||||
class: Drupal\update\UpdateFetcher
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\user\EventSubscriber;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Site\Settings;
|
||||
|
@ -35,10 +36,16 @@ class UserRequestSubscriber implements EventSubscriberInterface {
|
|||
* The current user.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager service.
|
||||
* @param \Drupal\Component\Datetime\TimeInterface|null $time
|
||||
* The time service.
|
||||
*/
|
||||
public function __construct(AccountInterface $account, EntityTypeManagerInterface $entity_type_manager) {
|
||||
public function __construct(AccountInterface $account, EntityTypeManagerInterface $entity_type_manager, protected ?TimeInterface $time = NULL) {
|
||||
$this->account = $account;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
if (!$time) {
|
||||
@trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3387233', E_USER_DEPRECATED);
|
||||
$this->time = \Drupal::service(TimeInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,11 +55,11 @@ class UserRequestSubscriber implements EventSubscriberInterface {
|
|||
* The event to process.
|
||||
*/
|
||||
public function onKernelTerminate(TerminateEvent $event) {
|
||||
if ($this->account->isAuthenticated() && REQUEST_TIME - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) {
|
||||
if ($this->account->isAuthenticated() && $this->time->getRequestTime() - $this->account->getLastAccessedTime() > Settings::get('session_write_interval', 180)) {
|
||||
// Do that no more than once per 180 seconds.
|
||||
/** @var \Drupal\user\UserStorageInterface $storage */
|
||||
$storage = $this->entityTypeManager->getStorage('user');
|
||||
$storage->updateLastAccessTimestamp($this->account, REQUEST_TIME);
|
||||
$storage->updateLastAccessTimestamp($this->account, $this->time->getRequestTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ services:
|
|||
- { name: event_subscriber }
|
||||
user_last_access_subscriber:
|
||||
class: Drupal\user\EventSubscriber\UserRequestSubscriber
|
||||
arguments: ['@current_user', '@entity_type.manager']
|
||||
arguments: ['@current_user', '@entity_type.manager', '@datetime.time']
|
||||
tags:
|
||||
- { name: event_subscriber }
|
||||
theme.negotiator.admin_theme:
|
||||
|
|
|
@ -227,11 +227,6 @@ parameters:
|
|||
count: 2
|
||||
path: lib/Drupal/Core/Asset/JsCollectionGrouper.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 1
|
||||
path: lib/Drupal/Core/Asset/JsCollectionRenderer.php
|
||||
|
||||
-
|
||||
message: "#^Call to method getDefinitions\\(\\) on an unknown class Drupal\\\\Core\\\\Plugin\\\\CategorizingPluginManagerTrait\\.$#"
|
||||
count: 1
|
||||
|
@ -242,11 +237,6 @@ parameters:
|
|||
count: 1
|
||||
path: lib/Drupal/Core/Block/BlockManager.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 3
|
||||
path: lib/Drupal/Core/Cache/ApcuBackend.php
|
||||
|
||||
-
|
||||
message: """
|
||||
#^Class Drupal\\\\Core\\\\Cache\\\\CacheFactory implements deprecated interface Symfony\\\\Component\\\\DependencyInjection\\\\ContainerAwareInterface\\:
|
||||
|
@ -271,26 +261,11 @@ parameters:
|
|||
count: 1
|
||||
path: lib/Drupal/Core/Cache/ChainedFastBackendFactory.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 4
|
||||
path: lib/Drupal/Core/Cache/DatabaseBackend.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 1
|
||||
path: lib/Drupal/Core/Cache/MemoryBackend.php
|
||||
|
||||
-
|
||||
message: "#^Constructor of class Drupal\\\\Core\\\\Cache\\\\NullBackend has an unused parameter \\$bin\\.$#"
|
||||
count: 1
|
||||
path: lib/Drupal/Core/Cache/NullBackend.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 2
|
||||
path: lib/Drupal/Core/Cache/PhpBackend.php
|
||||
|
||||
-
|
||||
message: "#^Call to method getDefinitions\\(\\) on an unknown class Drupal\\\\Core\\\\Plugin\\\\CategorizingPluginManagerTrait\\.$#"
|
||||
count: 1
|
||||
|
@ -613,11 +588,6 @@ parameters:
|
|||
count: 1
|
||||
path: lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 2
|
||||
path: lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php
|
||||
|
||||
-
|
||||
message: """
|
||||
#^Call to deprecated method getFromDriverName\\(\\) of class Drupal\\\\Core\\\\Extension\\\\DatabaseDriverList\\:
|
||||
|
@ -712,11 +682,6 @@ parameters:
|
|||
count: 9
|
||||
path: lib/Drupal/Core/FileTransfer/SSH.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 4
|
||||
path: lib/Drupal/Core/Flood/DatabaseBackend.php
|
||||
|
||||
-
|
||||
message: "#^Method Drupal\\\\Core\\\\Form\\\\FormBuilder\\:\\:setInvalidTokenError\\(\\) should return \\$this\\(Drupal\\\\Core\\\\Form\\\\FormBuilder\\) but return statement is missing\\.$#"
|
||||
count: 1
|
||||
|
@ -757,11 +722,6 @@ parameters:
|
|||
count: 4
|
||||
path: lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 1
|
||||
path: lib/Drupal/Core/KeyValueStore/KeyValueDatabaseExpirableFactory.php
|
||||
|
||||
-
|
||||
message: "#^Method Drupal\\\\Core\\\\KeyValueStore\\\\NullStorageExpirable\\:\\:setIfNotExists\\(\\) should return bool but return statement is missing\\.$#"
|
||||
count: 1
|
||||
|
@ -878,16 +838,6 @@ parameters:
|
|||
count: 1
|
||||
path: lib/Drupal/Core/Routing/MatcherDumper.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 2
|
||||
path: lib/Drupal/Core/Session/SessionHandler.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 1
|
||||
path: lib/Drupal/Core/Session/SessionManager.php
|
||||
|
||||
-
|
||||
message: "#^Variable \\$current might not be defined\\.$#"
|
||||
count: 1
|
||||
|
@ -1083,11 +1033,6 @@ parameters:
|
|||
count: 1
|
||||
path: modules/comment/src/CommentForm.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 2
|
||||
path: modules/comment/src/CommentStatistics.php
|
||||
|
||||
-
|
||||
message: "#^Method Drupal\\\\comment\\\\CommentTypeForm\\:\\:save\\(\\) should return int but return statement is missing\\.$#"
|
||||
count: 1
|
||||
|
@ -1984,11 +1929,6 @@ parameters:
|
|||
count: 1
|
||||
path: modules/path/src/Plugin/Field/FieldType/PathItem.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 1
|
||||
path: modules/path_alias/src/AliasManager.php
|
||||
|
||||
-
|
||||
message: """
|
||||
#^Call to deprecated method makeSequenceName\\(\\) of class Drupal\\\\Core\\\\Database\\\\Connection\\:
|
||||
|
@ -2052,11 +1992,6 @@ parameters:
|
|||
count: 1
|
||||
path: modules/search/src/Form/SearchPageFormBase.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 1
|
||||
path: modules/search/src/SearchIndex.php
|
||||
|
||||
-
|
||||
message: "#^Method Drupal\\\\search\\\\SearchPageRepository\\:\\:setDefaultSearchPage\\(\\) should return static\\(Drupal\\\\search\\\\SearchPageRepository\\) but return statement is missing\\.$#"
|
||||
count: 1
|
||||
|
@ -2312,11 +2247,6 @@ parameters:
|
|||
count: 1
|
||||
path: modules/user/src/Controller/UserAuthenticationController.php
|
||||
|
||||
-
|
||||
message: "#^Call to deprecated constant REQUEST_TIME\\: Deprecated in drupal\\:8\\.3\\.0 and is removed from drupal\\:11\\.0\\.0\\. Use \\\\Drupal\\:\\:time\\(\\)\\-\\>getRequestTime\\(\\); $#"
|
||||
count: 2
|
||||
path: modules/user/src/EventSubscriber/UserRequestSubscriber.php
|
||||
|
||||
-
|
||||
message: "#^Variable \\$route_object might not be defined\\.$#"
|
||||
count: 1
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\ApcuBackend;
|
||||
|
||||
/**
|
||||
|
@ -16,7 +17,7 @@ class ApcuBackendTest extends GenericCacheBackendUnitTestBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
protected function createCacheBackend($bin) {
|
||||
return new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum'));
|
||||
return new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum'), \Drupal::service(TimeInterface::class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\BackendChain;
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
|
||||
|
@ -16,10 +17,11 @@ class BackendChainTest extends GenericCacheBackendUnitTestBase {
|
|||
$chain = new BackendChain();
|
||||
|
||||
// We need to create some various backends in the chain.
|
||||
$time = \Drupal::service(TimeInterface::class);
|
||||
$chain
|
||||
->appendBackend(new MemoryBackend())
|
||||
->prependBackend(new MemoryBackend())
|
||||
->appendBackend(new MemoryBackend());
|
||||
->appendBackend(new MemoryBackend($time))
|
||||
->prependBackend(new MemoryBackend($time))
|
||||
->appendBackend(new MemoryBackend($time));
|
||||
|
||||
\Drupal::service('cache_tags.invalidator')->addInvalidator($chain);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\ChainedFastBackend;
|
||||
use Drupal\Core\Cache\DatabaseBackend;
|
||||
use Drupal\Core\Cache\PhpBackend;
|
||||
|
@ -20,8 +21,8 @@ class ChainedFastBackendTest extends GenericCacheBackendUnitTestBase {
|
|||
* A new ChainedFastBackend object.
|
||||
*/
|
||||
protected function createCacheBackend($bin) {
|
||||
$consistent_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags.invalidator.checksum'), $bin, \Drupal::service('serialization.phpserialize'), 100);
|
||||
$fast_backend = new PhpBackend($bin, \Drupal::service('cache_tags.invalidator.checksum'));
|
||||
$consistent_backend = new DatabaseBackend(\Drupal::service('database'), \Drupal::service('cache_tags.invalidator.checksum'), $bin, \Drupal::service('serialization.phpserialize'), \Drupal::service(TimeInterface::class), 100);
|
||||
$fast_backend = new PhpBackend($bin, \Drupal::service('cache_tags.invalidator.checksum'), \Drupal::service(TimeInterface::class));
|
||||
$backend = new ChainedFastBackend($consistent_backend, $fast_backend, $bin);
|
||||
// Explicitly register the cache bin as it can not work through the
|
||||
// cache bin list in the container.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\DatabaseBackend;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +33,14 @@ class DatabaseBackendTest extends GenericCacheBackendUnitTestBase {
|
|||
* A new DatabaseBackend object.
|
||||
*/
|
||||
protected function createCacheBackend($bin) {
|
||||
return new DatabaseBackend($this->container->get('database'), $this->container->get('cache_tags.invalidator.checksum'), $bin, $this->container->get('serialization.phpserialize'), static::$maxRows);
|
||||
return new DatabaseBackend(
|
||||
$this->container->get('database'),
|
||||
$this->container->get('cache_tags.invalidator.checksum'),
|
||||
$bin,
|
||||
$this->container->get('serialization.phpserialize'),
|
||||
\Drupal::service(TimeInterface::class),
|
||||
static::$maxRows,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\DatabaseBackendFactory;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
@ -54,7 +55,8 @@ class EndOfTransactionQueriesTest extends KernelTestBase {
|
|||
->addArgument(new Reference('database'))
|
||||
->addArgument(new Reference('cache_tags.invalidator.checksum'))
|
||||
->addArgument(new Reference('settings'))
|
||||
->addArgument(new Reference('serializer'));
|
||||
->addArgument(new Reference('serializer'))
|
||||
->addArgument(new Reference(TimeInterface::class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
|
||||
/**
|
||||
|
@ -18,7 +19,7 @@ class MemoryBackendTest extends GenericCacheBackendUnitTestBase {
|
|||
* A new MemoryBackend object.
|
||||
*/
|
||||
protected function createCacheBackend($bin) {
|
||||
$backend = new MemoryBackend();
|
||||
$backend = new MemoryBackend(\Drupal::service(TimeInterface::class));
|
||||
\Drupal::service('cache_tags.invalidator')->addInvalidator($backend);
|
||||
return $backend;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\PhpBackend;
|
||||
|
||||
/**
|
||||
|
@ -18,8 +19,7 @@ class PhpBackendTest extends GenericCacheBackendUnitTestBase {
|
|||
* A new PhpBackend object.
|
||||
*/
|
||||
protected function createCacheBackend($bin) {
|
||||
$backend = new PhpBackend($bin, \Drupal::service('cache_tags.invalidator.checksum'));
|
||||
return $backend;
|
||||
return new PhpBackend($bin, \Drupal::service('cache_tags.invalidator.checksum'), \Drupal::service(TimeInterface::class));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,11 @@ class DrupalKernelSiteTest extends KernelTestBase {
|
|||
$class = __CLASS__;
|
||||
$doc = <<<EOD
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
Symfony\Component\HttpFoundation\RequestStack: ~
|
||||
Drupal\Component\Datetime\TimeInterface:
|
||||
class: Drupal\Component\Datetime\Time
|
||||
# Add a new service.
|
||||
site.service.yml:
|
||||
class: $class
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\KernelTests\Core\Plugin;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Plugin\Context\EntityContextDefinition;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\plugin_test\Plugin\TestPluginManager;
|
||||
|
@ -45,7 +46,7 @@ abstract class PluginTestBase extends KernelTestBase {
|
|||
// as derivatives and ReflectionFactory.
|
||||
$this->testPluginManager = new TestPluginManager();
|
||||
$this->mockBlockManager = new MockBlockManager();
|
||||
$module_handler = new ModuleHandler($this->root, [], new MemoryBackend());
|
||||
$module_handler = new ModuleHandler($this->root, [], new MemoryBackend(\Drupal::service(TimeInterface::class)));
|
||||
$this->defaultsTestPluginManager = new DefaultsTestPluginManager($module_handler);
|
||||
|
||||
// The expected plugin definitions within each manager. Several tests assert
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Drupal\KernelTests\Core\Routing;
|
||||
|
||||
use ColinODell\PsrTestLogger\TestLogger;
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
|
||||
|
@ -97,7 +98,7 @@ class RouteProviderTest extends KernelTestBase {
|
|||
$this->fixtures = new RoutingFixtures();
|
||||
$this->state = new State(new KeyValueMemoryFactory());
|
||||
$this->currentPath = new CurrentPathStack(new RequestStack());
|
||||
$this->cache = new MemoryBackend();
|
||||
$this->cache = new MemoryBackend(\Drupal::service(TimeInterface::class));
|
||||
$this->pathProcessor = \Drupal::service('path_processor_manager');
|
||||
$this->cacheTagsInvalidator = \Drupal::service('cache_tags.invalidator');
|
||||
$this->installEntitySchema('path_alias');
|
||||
|
|
|
@ -561,13 +561,16 @@ abstract class KernelTestBase extends TestCase implements ServiceProviderInterfa
|
|||
// Keep the container object around for tests.
|
||||
$this->container = $container;
|
||||
|
||||
$container
|
||||
->register('datetime.time', 'Drupal\Component\Datetime\Time');
|
||||
$container
|
||||
->register('flood', 'Drupal\Core\Flood\MemoryBackend')
|
||||
->addArgument(new Reference('request_stack'));
|
||||
$container
|
||||
->register('lock', 'Drupal\Core\Lock\NullLockBackend');
|
||||
$container
|
||||
->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory');
|
||||
->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory')
|
||||
->addArgument(new Reference('datetime.time'));
|
||||
|
||||
// Use memory for key value storages to avoid database queries. Store the
|
||||
// key value factory on the test object so that key value storages persist
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Asset;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Asset\AssetResolver;
|
||||
use Drupal\Core\Asset\AttachedAssets;
|
||||
use Drupal\Core\Asset\AttachedAssetsInterface;
|
||||
|
@ -116,7 +117,7 @@ class AssetResolverTest extends UnitTestCase {
|
|||
$this->languageManager->expects($this->any())
|
||||
->method('getCurrentLanguage')
|
||||
->will($this->onConsecutiveCalls($english, $english, $japanese, $japanese));
|
||||
$this->cache = new TestMemoryBackend();
|
||||
$this->cache = new TestMemoryBackend(new Time());
|
||||
|
||||
$this->assetResolver = new AssetResolver($this->libraryDiscovery, $this->libraryDependencyResolver, $this->moduleHandler, $this->themeManager, $this->languageManager, $this->cache);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\BackendChain;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
|
@ -52,9 +53,10 @@ class BackendChainImplementationUnitTest extends UnitTestCase {
|
|||
parent::setUp();
|
||||
|
||||
// Set up three memory backends to be used in the chain.
|
||||
$this->firstBackend = new MemoryBackend();
|
||||
$this->secondBackend = new MemoryBackend();
|
||||
$this->thirdBackend = new MemoryBackend();
|
||||
$time = new Time();
|
||||
$this->firstBackend = new MemoryBackend($time);
|
||||
$this->secondBackend = new MemoryBackend($time);
|
||||
$this->thirdBackend = new MemoryBackend($time);
|
||||
|
||||
// Set an initial fixed dataset for all testing. The next three data
|
||||
// collections will test two edge cases (last backend has the data, and
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\ChainedFastBackend;
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
@ -49,7 +50,7 @@ class ChainedFastBackendTest extends UnitTestCase {
|
|||
$consistent_cache->expects($this->never())
|
||||
->method('getMultiple');
|
||||
|
||||
$fast_cache = new MemoryBackend();
|
||||
$fast_cache = new MemoryBackend(new Time());
|
||||
$fast_cache->set('foo', 'baz');
|
||||
|
||||
$chained_fast_backend = new ChainedFastBackend(
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Component\Serialization\PhpSerialize;
|
||||
use Drupal\Core\Cache\CacheTagsChecksumInterface;
|
||||
use Drupal\Core\Cache\DatabaseBackend;
|
||||
|
@ -28,7 +29,8 @@ class DatabaseBackendFactoryTest extends UnitTestCase {
|
|||
$this->prophesize(Connection::class)->reveal(),
|
||||
$this->prophesize(CacheTagsChecksumInterface::class)->reveal(),
|
||||
new Settings($settings),
|
||||
new PhpSerialize()
|
||||
new PhpSerialize(),
|
||||
$this->prophesize(TimeInterface::class)->reveal(),
|
||||
);
|
||||
|
||||
$this->assertSame($expected_max_rows_foo, $database_backend_factory->get('foo')->getMaxRows());
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Cache;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Cache\CacheRedirect;
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
|
@ -125,7 +126,7 @@ class VariationCacheTest extends UnitTestCase {
|
|||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->requestStack = $this->prophesize(RequestStack::class);
|
||||
$this->memoryBackend = new MemoryBackend();
|
||||
$this->memoryBackend = new MemoryBackend(new Time());
|
||||
$this->cacheContextsManager = $this->prophesize(CacheContextsManager::class);
|
||||
|
||||
$housing_type = &$this->housingType;
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Config\Entity;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Component\Uuid\UuidInterface;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
|
||||
|
@ -139,7 +140,7 @@ class ConfigEntityStorageTest extends UnitTestCase {
|
|||
$entity_query_factory = $this->prophesize(QueryFactoryInterface::class);
|
||||
$entity_query_factory->get($entity_type, 'AND')->willReturn($this->entityQuery->reveal());
|
||||
|
||||
$this->entityStorage = new ConfigEntityStorage($entity_type, $this->configFactory->reveal(), $this->uuidService->reveal(), $this->languageManager->reveal(), new MemoryCache());
|
||||
$this->entityStorage = new ConfigEntityStorage($entity_type, $this->configFactory->reveal(), $this->uuidService->reveal(), $this->languageManager->reveal(), new MemoryCache(new Time()));
|
||||
$this->entityStorage->setModuleHandler($this->moduleHandler->reveal());
|
||||
|
||||
$entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class);
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Entity\KeyValueStore;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCache;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
|
@ -137,7 +138,7 @@ class KeyValueEntityStorageTest extends UnitTestCase {
|
|||
->method('getCurrentLanguage')
|
||||
->willReturn($language);
|
||||
|
||||
$this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager, new MemoryCache());
|
||||
$this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager, new MemoryCache(new Time()));
|
||||
$this->entityStorage->setModuleHandler($this->moduleHandler);
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Entity\Sql;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCache;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Entity\EntityFieldManager;
|
||||
|
@ -426,7 +427,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->willReturn($schema_handler);
|
||||
|
||||
$storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
|
||||
->setConstructorArgs([$this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal()])
|
||||
->setConstructorArgs([$this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(new Time()), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal()])
|
||||
->onlyMethods(['getStorageSchema'])
|
||||
->getMock();
|
||||
|
||||
|
@ -1175,7 +1176,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->getActiveFieldStorageDefinitions($this->entityType->id())
|
||||
->willReturn($this->fieldDefinitions);
|
||||
|
||||
$this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal());
|
||||
$this->entityStorage = new SqlContentEntityStorage($this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(new Time()), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal());
|
||||
$this->entityStorage->setModuleHandler($this->moduleHandler);
|
||||
}
|
||||
|
||||
|
@ -1249,7 +1250,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->willReturn($this->entityType);
|
||||
|
||||
$entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
|
||||
->setConstructorArgs([$this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal()])
|
||||
->setConstructorArgs([$this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(new Time()), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal()])
|
||||
->onlyMethods(['getFromStorage', 'invokeStorageLoadHook', 'initTableLayout'])
|
||||
->getMock();
|
||||
$entity_storage->method('invokeStorageLoadHook')
|
||||
|
@ -1309,7 +1310,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->willReturn($this->entityType);
|
||||
|
||||
$entity_storage = $this->getMockBuilder('Drupal\Core\Entity\Sql\SqlContentEntityStorage')
|
||||
->setConstructorArgs([$this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal()])
|
||||
->setConstructorArgs([$this->entityType, $this->connection, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(new Time()), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal()])
|
||||
->onlyMethods(['getFromStorage', 'invokeStorageLoadHook', 'initTableLayout'])
|
||||
->getMock();
|
||||
$entity_storage->method('invokeStorageLoadHook')
|
||||
|
@ -1370,7 +1371,7 @@ class SqlContentEntityStorageTest extends UnitTestCase {
|
|||
->getActiveFieldStorageDefinitions($this->entityType->id())
|
||||
->willReturn($this->fieldDefinitions);
|
||||
|
||||
$this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal());
|
||||
$this->entityStorage = new SqlContentEntityStorage($this->entityType, $database, $this->entityFieldManager->reveal(), $this->cache, $this->languageManager, new MemoryCache(new Time()), $this->entityTypeBundleInfo, $this->entityTypeManager->reveal());
|
||||
|
||||
$result = $this->entityStorage->hasData();
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\EventSubscriber;
|
||||
|
||||
use Drupal\Component\Datetime\TimeInterface;
|
||||
use Drupal\Core\Cache\Context\CacheContextsManager;
|
||||
use Drupal\Core\EventSubscriber\FinishResponseSubscriber;
|
||||
use Drupal\Core\Language\Language;
|
||||
|
@ -58,6 +59,13 @@ class FinishResponseSubscriberTest extends UnitTestCase {
|
|||
*/
|
||||
protected $cacheContextsManager;
|
||||
|
||||
/**
|
||||
* The mock time service.
|
||||
*
|
||||
* @var \Drupal\Component\Datetime\TimeInterface|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $time;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
@ -66,6 +74,7 @@ class FinishResponseSubscriberTest extends UnitTestCase {
|
|||
$this->requestPolicy = $this->createMock(RequestPolicyInterface::class);
|
||||
$this->responsePolicy = $this->createMock(ResponsePolicyInterface::class);
|
||||
$this->cacheContextsManager = $this->createMock(CacheContextsManager::class);
|
||||
$this->time = $this->createMock(TimeInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,6 +89,7 @@ class FinishResponseSubscriberTest extends UnitTestCase {
|
|||
$this->requestPolicy,
|
||||
$this->responsePolicy,
|
||||
$this->cacheContextsManager,
|
||||
$this->time,
|
||||
FALSE
|
||||
);
|
||||
|
||||
|
@ -110,6 +120,7 @@ class FinishResponseSubscriberTest extends UnitTestCase {
|
|||
$this->requestPolicy,
|
||||
$this->responsePolicy,
|
||||
$this->cacheContextsManager,
|
||||
$this->time,
|
||||
FALSE
|
||||
);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Render;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Cache\MemoryBackend;
|
||||
use Drupal\Core\Cache\VariationCache;
|
||||
|
@ -80,8 +81,8 @@ class RendererBubblingTest extends RendererTestBase {
|
|||
$bin = $this->randomMachineName();
|
||||
|
||||
$this->setUpRequest();
|
||||
$this->memoryCache = new VariationCache($this->requestStack, new MemoryBackend(), $this->cacheContextsManager);
|
||||
$custom_cache = new VariationCache($this->requestStack, new MemoryBackend(), $this->cacheContextsManager);
|
||||
$this->memoryCache = new VariationCache($this->requestStack, new MemoryBackend(new Time($this->requestStack)), $this->cacheContextsManager);
|
||||
$custom_cache = new VariationCache($this->requestStack, new MemoryBackend(new Time($this->requestStack)), $this->cacheContextsManager);
|
||||
|
||||
$this->cacheFactory->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Render;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Cache\Context\ContextCacheKeys;
|
||||
|
@ -222,7 +223,7 @@ abstract class RendererTestBase extends UnitTestCase {
|
|||
* Sets up a memory-based render cache back-end.
|
||||
*/
|
||||
protected function setupMemoryCache() {
|
||||
$this->memoryCache = $this->memoryCache ?: new VariationCache($this->requestStack, new MemoryBackend(), $this->cacheContextsManager);
|
||||
$this->memoryCache = $this->memoryCache ?: new VariationCache($this->requestStack, new MemoryBackend(new Time($this->requestStack)), $this->cacheContextsManager);
|
||||
|
||||
$this->cacheFactory->expects($this->atLeastOnce())
|
||||
->method('get')
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\Core\Session;
|
||||
|
||||
use Drupal\Component\Datetime\Time;
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCache;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Session\PermissionChecker;
|
||||
|
@ -98,7 +99,7 @@ class UserSessionTest extends UnitTestCase {
|
|||
]);
|
||||
|
||||
$role_storage = $this->getMockBuilder('Drupal\user\RoleStorage')
|
||||
->setConstructorArgs(['role', new MemoryCache()])
|
||||
->setConstructorArgs(['role', new MemoryCache(new Time())])
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['loadMultiple'])
|
||||
->getMock();
|
||||
|
|
Loading…
Reference in New Issue