TYPO3 CMS  TYPO3_6-2
AbstractBackend.php
Go to the documentation of this file.
1 <?php
3 
27 
28  const DATETIME_EXPIRYTIME_UNLIMITED = '9999-12-31T23:59:59+0000';
29  const UNLIMITED_LIFETIME = 0;
35  protected $cache;
36 
40  protected $cacheIdentifier;
41 
51  protected $context;
52 
58  protected $defaultLifetime = 3600;
59 
68  public function __construct($context, array $options = array()) {
69  $this->context = $context;
70  if (is_array($options) || $options instanceof \ArrayAccess) {
71  foreach ($options as $optionKey => $optionValue) {
72  $methodName = 'set' . ucfirst($optionKey);
73  if (method_exists($this, $methodName)) {
74  $this->{$methodName}($optionValue);
75  } else {
76  throw new \InvalidArgumentException('Invalid cache backend option "' . $optionKey . '" for backend of type "' . get_class($this) . '"', 1231267498);
77  }
78  }
79  }
80  }
81 
89  public function setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache) {
90  $this->cache = $cache;
91  $this->cacheIdentifier = $this->cache->getIdentifier();
92  }
93 
103  if (!is_int($defaultLifetime) || $defaultLifetime < 0) {
104  throw new \InvalidArgumentException('The default lifetime must be given as a positive integer.', 1233072774);
105  }
106  $this->defaultLifetime = $defaultLifetime;
107  }
108 
116  protected function calculateExpiryTime($lifetime = NULL) {
117  if ($lifetime === self::UNLIMITED_LIFETIME || $lifetime === NULL && $this->defaultLifetime === self::UNLIMITED_LIFETIME) {
118  $expiryTime = new \DateTime(self::DATETIME_EXPIRYTIME_UNLIMITED, new \DateTimeZone('UTC'));
119  } else {
120  if ($lifetime === NULL) {
121  $lifetime = $this->defaultLifetime;
122  }
123  $expiryTime = new \DateTime('now +' . $lifetime . ' seconds', new \DateTimeZone('UTC'));
124  }
125  return $expiryTime;
126  }
127 
128 }
setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
__construct($context, array $options=array())