TYPO3 CMS  TYPO3_8-7
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 
28 abstract class AbstractFrontend implements FrontendInterface
29 {
35  protected $identifier;
36 
40  protected $backend;
41 
50  {
51  if (preg_match(self::PATTERN_ENTRYIDENTIFIER, $identifier) !== 1) {
52  throw new \InvalidArgumentException('"' . $identifier . '" is not a valid cache identifier.', 1203584729);
53  }
54  $this->identifier = $identifier;
55  $this->backend = $backend;
56  $this->backend->setCache($this);
57  }
58 
65  public function getIdentifier()
66  {
67  return $this->identifier;
68  }
69 
76  public function getBackend()
77  {
78  return $this->backend;
79  }
80 
89  public function has($entryIdentifier)
90  {
91  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
92  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058486);
93  }
94  return $this->backend->has($entryIdentifier);
95  }
96 
105  public function remove($entryIdentifier)
106  {
107  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
108  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058495);
109  }
110  return $this->backend->remove($entryIdentifier);
111  }
112 
118  public function flush()
119  {
120  $this->backend->flush();
121  }
122 
129  public function flushByTags(array $tags)
130  {
131  foreach ($tags as $tag) {
132  if (!$this->isValidTag($tag)) {
133  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057360);
134  }
135  }
136  if ($this->backend instanceof TaggableBackendInterface) {
137  $this->backend->flushByTags($tags);
138  }
139  }
140 
148  public function flushByTag($tag)
149  {
150  if (!$this->isValidTag($tag)) {
151  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057359);
152  }
153  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']['flushByTag'])) {
154  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']['flushByTag'] as $_funcRef) {
155  $params = ['tag' => $tag];
156  GeneralUtility::callUserFunction($_funcRef, $params, $this);
157  }
158  }
159  if ($this->backend instanceof TaggableBackendInterface) {
160  $this->backend->flushByTag($tag);
161  }
162  }
163 
169  public function collectGarbage()
170  {
171  $this->backend->collectGarbage();
172  }
173 
182  {
183  return preg_match(self::PATTERN_ENTRYIDENTIFIER, $identifier) === 1;
184  }
185 
193  public function isValidTag($tag)
194  {
195  if (!is_array($tag)) {
196  return preg_match(self::PATTERN_TAG, $tag) === 1;
197  }
198  foreach ($tag as $tagValue) {
199  if (!$this->isValidTag($tagValue)) {
200  return false;
201  }
202  }
203  return true;
204  }
205 }
static callUserFunction($funcName, &$params, &$ref, $_='', $errorMode=0)
__construct($identifier, BackendInterface $backend)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']