‪TYPO3CMS  9.5
AbstractFrontend.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
25 abstract class ‪AbstractFrontend implements ‪FrontendInterface
26 {
32  protected ‪$identifier;
33 
37  protected ‪$backend;
38 
47  {
48  if (preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) !== 1) {
49  throw new \InvalidArgumentException('"' . ‪$identifier . '" is not a valid cache identifier.', 1203584729);
50  }
51  $this->identifier = ‪$identifier;
52  $this->backend = ‪$backend;
53  $this->backend->‪setCache($this);
54  }
55 
61  public function ‪getIdentifier()
62  {
63  return ‪$this->identifier;
64  }
65 
71  public function ‪getBackend()
72  {
73  return ‪$this->backend;
74  }
75 
83  public function ‪has($entryIdentifier)
84  {
85  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
86  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058486);
87  }
88  return $this->backend->has($entryIdentifier);
89  }
90 
98  public function remove($entryIdentifier)
99  {
100  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
101  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058495);
102  }
103  return $this->backend->remove($entryIdentifier);
104  }
105 
109  public function ‪flush()
110  {
111  $this->backend->flush();
112  }
113 
120  public function ‪flushByTags(array $tags)
121  {
122  foreach ($tags as $tag) {
123  if (!$this->‪isValidTag($tag)) {
124  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057360);
125  }
126  }
127  if ($this->backend instanceof ‪TaggableBackendInterface) {
128  $this->backend->flushByTags($tags);
129  }
130  }
131 
138  public function ‪flushByTag($tag)
139  {
140  if (!$this->‪isValidTag($tag)) {
141  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057359);
142  }
143 
144  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']['flushByTag'] ?? [] as $_funcRef) {
145  $params = ['tag' => $tag];
146  GeneralUtility::callUserFunction($_funcRef, $params, $this);
147  }
148 
149  if ($this->backend instanceof ‪TaggableBackendInterface) {
150  $this->backend->flushByTag($tag);
151  }
152  }
153 
157  public function ‪collectGarbage()
158  {
159  $this->backend->collectGarbage();
160  }
161 
169  {
170  return preg_match(self::PATTERN_ENTRYIDENTIFIER, ‪$identifier) === 1;
171  }
172 
179  public function ‪isValidTag($tag)
180  {
181  if (!is_array($tag)) {
182  return preg_match(self::PATTERN_TAG, $tag) === 1;
183  }
184  foreach ($tag as $tagValue) {
185  if (!$this->‪isValidTag($tagValue)) {
186  return false;
187  }
188  }
189  return true;
190  }
191 }
‪TYPO3\CMS\Core\Cache\Frontend
Definition: AbstractFrontend.php:2
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$backend
‪AbstractBackend TaggableBackendInterface $backend
Definition: AbstractFrontend.php:35
‪TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface
Definition: TaggableBackendInterface.php:21
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\has
‪bool has($entryIdentifier)
Definition: AbstractFrontend.php:81
‪TYPO3\CMS\Core\Cache\Backend\BackendInterface
Definition: BackendInterface.php:23
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getIdentifier
‪string getIdentifier()
Definition: AbstractFrontend.php:59
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$identifier
‪string $identifier
Definition: AbstractFrontend.php:31
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidEntryIdentifier
‪bool isValidEntryIdentifier($identifier)
Definition: AbstractFrontend.php:166
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\__construct
‪__construct($identifier, BackendInterface $backend)
Definition: AbstractFrontend.php:44
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTags
‪flushByTags(array $tags)
Definition: AbstractFrontend.php:118
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flushByTag
‪flushByTag($tag)
Definition: AbstractFrontend.php:136
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidTag
‪bool isValidTag($tag)
Definition: AbstractFrontend.php:177
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend
Definition: AbstractBackend.php:26
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\collectGarbage
‪collectGarbage()
Definition: AbstractFrontend.php:155
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\getBackend
‪BackendInterface getBackend()
Definition: AbstractFrontend.php:69
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Cache\Backend\AbstractBackend\setCache
‪setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
Definition: AbstractBackend.php:89
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\flush
‪flush()
Definition: AbstractFrontend.php:107
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:26