Skip to content
Snippets Groups Projects
Commit fd75fa21 authored by catch's avatar catch
Browse files

Issue #3113971 by Spokje, mondrake, acbramley, phenaproxima, andypost,...

Issue #3113971 by Spokje, mondrake, acbramley, phenaproxima, andypost, murilohp, mpdonadio, ravi.shankar, pavnish, pifagor, vladbo, JeroenT, voleger, Taran2L: Replace REQUEST_TIME in services
parent 9231c9cf
No related branches found
No related tags found
26 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #93815 passed
Pipeline: drupal

#93816

    Showing
    with 226 additions and 56 deletions
    ......@@ -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 @@ public function render(array $js_assets) {
    // 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 @@ public function __construct(Connection $connection, SessionInterface $session, C
    $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 @@ protected function prepareItem($cache, $allow_invalid) {
    $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 @@ public function invalidate($cid) {
    */
    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 @@ public function invalidateMultiple(array $cids) {
    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 @@ public function __construct($root, $site_path, CacheTagsChecksumInterface $check
    * 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 @@
    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 @@ public function __construct(
    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 @@ public function __construct(
    @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 @@ protected function prepareItem($cache, $allow_invalid) {
    $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 @@ public function invalidateMultiple(array $cids) {
    $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 @@ public function invalidateMultiple(array $cids) {
    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 @@ public function garbageCollection() {
    $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 @@ public function __construct(Connection $connection, CacheTagsChecksumInterface $
    @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 @@ public function __construct(Connection $connection, CacheTagsChecksumInterface $
    */
    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 @@ protected function prepareItem($cache, $allow_invalid) {
    $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 @@ public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
    $this->cache[$cid] = (object) [
    'cid' => $cid,
    'data' => serialize($data),
    'created' => $this->getRequestTime(),
    'created' => $this->time->getRequestTime(),
    'expire' => $expire,
    'tags' => $tags,
    ];
    ......@@ -148,7 +162,7 @@ public function deleteAll() {
    */
    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 @@ public function invalidate($cid) {
    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 @@ public function invalidateMultiple(array $cids) {
    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 @@ public function invalidateTags(array $tags) {
    */
    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 @@ public function removeBin() {
    * @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 @@ protected function prepareItem($cache, $allow_invalid = FALSE) {
    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 @@ public function set($cid, $data, $expire = MemoryCacheInterface::CACHE_PERMANENT
    $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 @@ protected function prepareItem($cache, $allow_invalid) {
    }
    // 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 @@ public function invalidate($cid) {
    */
    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 @@ public function __construct(CacheTagsChecksumInterface $checksum_provider) {
    * 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 @@ public function __construct(StorageInterface $source_storage, StorageInterface $
    $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 @@ public function __construct(StorageInterface $source_storage, StorageInterface $
    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 @@ protected function setResponseCacheable(Response $response, Request $request) {
    // 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 @@ protected function doInsert($name, $window, $identifier) {
    ->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 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL)
    $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 @@ public function isAllowed($name, $threshold, $window = 3600, $identifier = NULL)
    public function garbageCollection() {
    try {
    $this->connection->delete(static::TABLE_NAME)
    ->condition('expiration', REQUEST_TIME, '<')
    ->condition('expiration', $this->time->getRequestTime(), '<')
    ->execute();
    }
    catch (\Exception $e) {
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment