‪TYPO3CMS  ‪main
AbstractBackend.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Log\LoggerAwareInterface;
19 use Psr\Log\LoggerAwareTrait;
23 
27 abstract class ‪AbstractBackend implements ‪BackendInterface, LoggerAwareInterface
28 {
29  use LoggerAwareTrait;
30 
31  public const ‪DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000';
32  public const ‪UNLIMITED_LIFETIME = 0;
33 
39  protected ‪$cache;
40 
44  protected ‪$cacheIdentifier;
45 
54  protected ‪$context;
55 
61  protected ‪$defaultLifetime = 3600;
62 
70  public function ‪__construct(‪$context, array $options = [])
71  {
72  $this->context = ‪$context;
73  foreach ($options as $optionKey => $optionValue) {
74  $methodName = 'set' . ucfirst($optionKey);
75  if (method_exists($this, $methodName)) {
76  $this->{$methodName}($optionValue);
77  } else {
78  throw new \InvalidArgumentException('Invalid cache backend option "' . $optionKey . '" for backend of type "' . static::class . '"', 1231267498);
79  }
80  }
81  if ($this->logger === null) {
82  $this->setLogger(
83  GeneralUtility::makeInstance(LogManager::class)
84  ->getLogger(static::class)
85  );
86  }
87  }
88 
95  {
96  $this->cache = ‪$cache;
97  $this->cacheIdentifier = $this->cache->‪getIdentifier();
98  }
99 
107  {
108  if (!is_int(‪$defaultLifetime) || ‪$defaultLifetime < 0) {
109  throw new \InvalidArgumentException('The default lifetime must be given as a positive integer.', 1233072774);
110  }
111  $this->defaultLifetime = ‪$defaultLifetime;
112  }
113 
124  public function ‪flushByTags(array $tags)
125  {
126  // todo: flushByTag is not necessarily implemented since it's neither defined of the interface, nor defined in
127  // this class as abstract method. Therefore this potentially triggers a fatal error during runtime.
128  array_walk($tags, $this->flushByTag(...));
129  }
130 
138  protected function ‪calculateExpiryTime($lifetime = null)
139  {
140  if ($lifetime === self::UNLIMITED_LIFETIME || $lifetime === null && $this->defaultLifetime === self::UNLIMITED_LIFETIME) {
141  $expiryTime = new \DateTime(self::DATETIME_EXPIRYTIME_UNLIMITED, new \DateTimeZone('UTC'));
142  } else {
143  if ($lifetime === null) {
144  $lifetime = ‪$this->defaultLifetime;
145  }
146  $expiryTime = new \DateTime('now +' . $lifetime . ' seconds', new \DateTimeZone('UTC'));
147  }
148  return $expiryTime;
149  }
150 }
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\calculateExpiryTime
‪DateTime calculateExpiryTime($lifetime=null)
Definition: AbstractBackend.php:134
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface\getIdentifier
‪string getIdentifier()
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$cache
‪FrontendInterface $cache
Definition: AbstractBackend.php:38
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\setCache
‪setCache(FrontendInterface $cache)
Definition: AbstractBackend.php:90
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\UNLIMITED_LIFETIME
‪const UNLIMITED_LIFETIME
Definition: AbstractBackend.php:32
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\__construct
‪__construct($context, array $options=[])
Definition: AbstractBackend.php:66
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$defaultLifetime
‪int $defaultLifetime
Definition: AbstractBackend.php:57
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\flushByTags
‪flushByTags(array $tags)
Definition: AbstractBackend.php:120
‪TYPO3\CMS\Core\Cache\Backend\BackendInterface
Definition: BackendInterface.php:25
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\setDefaultLifetime
‪setDefaultLifetime($defaultLifetime)
Definition: AbstractBackend.php:102
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\DATETIME_EXPIRYTIME_UNLIMITED
‪const DATETIME_EXPIRYTIME_UNLIMITED
Definition: AbstractBackend.php:31
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$cacheIdentifier
‪string $cacheIdentifier
Definition: AbstractBackend.php:42
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:28
‪TYPO3\CMS\Core\Log\LogManager
Definition: LogManager.php:33
‪TYPO3\CMS\Core\Cache\Backend
Definition: AbstractBackend.php:16
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\$context
‪string $context
Definition: AbstractBackend.php:51
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52