‪TYPO3CMS  9.5
VariableFrontend.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 
19 
24 {
35  public function set($entryIdentifier, $variable, array $tags = [], $lifetime = null)
36  {
37  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
38  throw new \InvalidArgumentException(
39  '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
40  1233058264
41  );
42  }
43  foreach ($tags as $tag) {
44  if (!$this->‪isValidTag($tag)) {
45  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058269);
46  }
47  }
48 
49  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_variablefrontend.php']['set'] ?? [] as $_funcRef) {
50  $params = [
51  'entryIdentifier' => &$entryIdentifier,
52  'variable' => &$variable,
53  'tags' => &$tags,
54  'lifetime' => &$lifetime
55  ];
56  GeneralUtility::callUserFunction($_funcRef, $params, $this);
57  }
58  if (!$this->backend instanceof ‪TransientBackendInterface) {
59  $variable = serialize($variable);
60  }
61  $this->backend->set($entryIdentifier, $variable, $tags, $lifetime);
62  }
63 
72  public function get($entryIdentifier)
73  {
74  if (!$this->‪isValidEntryIdentifier($entryIdentifier)) {
75  throw new \InvalidArgumentException(
76  '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
77  1233058294
78  );
79  }
80  $rawResult = $this->backend->get($entryIdentifier);
81  if ($rawResult === false) {
82  return false;
83  }
84  return $this->backend instanceof ‪TransientBackendInterface ? $rawResult : unserialize($rawResult);
85  }
86 
96  public function ‪getByTag($tag)
97  {
98  trigger_error('VariableFrontend->getByTag() will be removed in TYPO3 v10.0. Avoid using this method since it is not compliant to PSR-6.', E_USER_DEPRECATED);
99  if (!$this->‪isValidTag($tag)) {
100  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058312);
101  }
102  $entries = [];
103  $identifiers = $this->backend->findIdentifiersByTag($tag);
104  foreach ($identifiers as ‪$identifier) {
105  $rawResult = $this->backend->get(‪$identifier);
106  if ($rawResult !== false) {
107  $entries[] = $this->backend instanceof ‪TransientBackendInterface ? $rawResult : unserialize($rawResult);
108  }
109  }
110  return $entries;
111  }
112 }
‪TYPO3\CMS\Core\Cache\Backend\TransientBackendInterface
Definition: TransientBackendInterface.php:32
‪TYPO3\CMS\Core\Cache\Frontend
Definition: AbstractFrontend.php:2
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\$identifier
‪string $identifier
Definition: AbstractFrontend.php:31
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
Definition: VariableFrontend.php:24
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidEntryIdentifier
‪bool isValidEntryIdentifier($identifier)
Definition: AbstractFrontend.php:166
‪TYPO3\CMS\Core\Cache\Frontend\VariableFrontend\getByTag
‪array getByTag($tag)
Definition: VariableFrontend.php:96
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend\isValidTag
‪bool isValidTag($tag)
Definition: AbstractFrontend.php:177
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:26