TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AbstractFrontend.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Cache\Frontend;
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 
119  public function flush()
120  {
121  $this->backend->flush();
122  }
123 
131  public function flushByTags(array $tags)
132  {
133  foreach ($tags as $tag) {
134  if (!$this->isValidTag($tag)) {
135  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057360);
136  }
137  }
138  if ($this->backend instanceof TaggableBackendInterface) {
139  $this->backend->flushByTags($tags);
140  }
141  }
142 
151  public function flushByTag($tag)
152  {
153  if (!$this->isValidTag($tag)) {
154  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057359);
155  }
156  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']['flushByTag'])) {
157  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_abstractfrontend.php']['flushByTag'] as $_funcRef) {
158  $params = ['tag' => $tag];
159  GeneralUtility::callUserFunction($_funcRef, $params, $this);
160  }
161  }
162  if ($this->backend instanceof TaggableBackendInterface) {
163  $this->backend->flushByTag($tag);
164  }
165  }
166 
173  public function collectGarbage()
174  {
175  $this->backend->collectGarbage();
176  }
177 
186  {
187  return preg_match(self::PATTERN_ENTRYIDENTIFIER, $identifier) === 1;
188  }
189 
197  public function isValidTag($tag)
198  {
199  if (!is_array($tag)) {
200  return preg_match(self::PATTERN_TAG, $tag) === 1;
201  }
202  foreach ($tag as $tagValue) {
203  if (!$this->isValidTag($tagValue)) {
204  return false;
205  }
206  }
207  return true;
208  }
209 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
__construct($identifier, BackendInterface $backend)
static callUserFunction($funcName, &$params, &$ref, $_= '', $errorMode=0)