‪TYPO3CMS  10.4
AbstractFrontend.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 
22 
26 abstract class ‪AbstractFrontend implements ‪FrontendInterface
27 {
33  protected ‪$identifier;
34 
38  protected ‪$backend;
39 
48  {
49  if (preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) !== 1) {
50  throw new \InvalidArgumentException('"' . ‪$identifier . '" is not a valid cache identifier.', 1203584729);
51  }
52  if (strpos(‪$identifier, 'cache_') === 0) {
53  trigger_error('Setting up a cache as in "' . ‪$identifier . '" with the "cache_" prefix is not necessary anymore, and should be called without the cache prefix.', E_USER_DEPRECATED);
54  ‪$identifier = substr(‪$identifier, 6);
55  }
56  $this->identifier = ‪$identifier;
57  $this->backend = ‪$backend;
58  $this->backend->‪setCache($this);
59  }
60 
66  public function ‪getIdentifier()
67  {
68  return ‪$this->identifier;
69  }
70 
76  public function ‪getBackend()
77  {
78  return ‪$this->backend;
79  }
80 
88  public function ‪has($entryIdentifier)
89  {
90  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
91  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058486);
92  }
93  return $this->backend->has($entryIdentifier);
94  }
95 
103  public function remove($entryIdentifier)
104  {
105  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
106  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058495);
107  }
108  return $this->backend->remove($entryIdentifier);
109  }
110 
114  public function ‪flush()
115  {
116  $this->backend->flush();
117  }
118 
125  public function ‪flushByTags(array $tags)
126  {
127  foreach ($tags as $tag) {
128  if (!$this->‪isValidTag($tag)) {
129  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057360);
130  }
131  }
132  if ($this->backend instanceof ‪TaggableBackendInterface) {
133  $this->backend->flushByTags($tags);
134  }
135  }
136 
143  public function ‪flushByTag($tag)
144  {
145  if (!$this->‪isValidTag($tag)) {
146  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057359);
147  }
148 
149  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']['flushByTag'] ?? [] as $_funcRef) {
150  $params = ['tag' => $tag];
151  GeneralUtility::callUserFunction($_funcRef, $params, $this);
152  }
153 
154  if ($this->backend instanceof ‪TaggableBackendInterface) {
155  $this->backend->flushByTag($tag);
156  }
157  }
158 
162  public function ‪collectGarbage()
163  {
164  $this->backend->collectGarbage();
165  }
166 
174  {
175  return preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) === 1;
176  }
177 
184  public function ‪isValidTag($tag)
185  {
186  if (!is_array($tag)) {
187  return preg_match(self::PATTERN_TAG, $tag) === 1;
188  }
189  foreach ($tag as $tagValue) {
190  if (!$this->‪isValidTag($tagValue)) {
191  return false;
192  }
193  }
194  return true;
195  }
196 }
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\setCache
‪setCache(FrontendInterface $cache)
Definition: AbstractBackend.php:89
‪TYPO3\CMS\Core\Cache\Frontend
Definition: AbstractFrontend.php:16
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$backend
‪AbstractBackend TaggableBackendInterface $backend
Definition: AbstractFrontend.php:36
‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface
Definition: TaggableBackendInterface.php:22
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\has
‪bool has($entryIdentifier)
Definition: AbstractFrontend.php:86
‪TYPO3\CMS\Core\Cache\Backend\BackendInterface
Definition: BackendInterface.php:25
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getIdentifier
‪string getIdentifier()
Definition: AbstractFrontend.php:64
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$identifier
‪string $identifier
Definition: AbstractFrontend.php:32
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidEntryIdentifier
‪bool isValidEntryIdentifier($identifier)
Definition: AbstractFrontend.php:171
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\__construct
‪__construct($identifier, BackendInterface $backend)
Definition: AbstractFrontend.php:45
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTags
‪flushByTags(array $tags)
Definition: AbstractFrontend.php:123
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTag
‪flushByTag($tag)
Definition: AbstractFrontend.php:141
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidTag
‪bool isValidTag($tag)
Definition: AbstractFrontend.php:182
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\collectGarbage
‪collectGarbage()
Definition: AbstractFrontend.php:160
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getBackend
‪BackendInterface getBackend()
Definition: AbstractFrontend.php:74
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flush
‪flush()
Definition: AbstractFrontend.php:112
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:27