|
4 | 4 |
|
5 | 5 | namespace Weakbit\LuceneCache\Cache\Frontend; |
6 | 6 |
|
7 | | -use TYPO3\CMS\Core\Cache\Exception; |
8 | | -use TYPO3\CMS\Core\Cache\Exception\InvalidDataException; |
9 | | -use MessagePack\BufferUnpacker; |
10 | | -use MessagePack\Packer; |
11 | | -use TYPO3\CMS\Core\Cache\Backend\TransientBackendInterface; |
12 | | -use TYPO3\CMS\Core\Utility\GeneralUtility; |
13 | 7 | use TYPO3\CMS\Core\Cache\Backend\BackendInterface; |
14 | | -use Weakbit\LuceneCache\Transformer\PageTransformer; |
15 | | -use Weakbit\LuceneCache\Transformer\UriTransformer; |
| 8 | + |
| 9 | +use function trigger_deprecation; |
16 | 10 |
|
17 | 11 | class VariableFrontend extends \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend |
18 | 12 | { |
19 | | - protected bool $messagePack = false; |
20 | | - |
21 | | - protected bool $igBinary = false; |
22 | | - |
23 | 13 | public function __construct($identifier, BackendInterface $backend) |
24 | 14 | { |
25 | 15 | parent::__construct($identifier, $backend); |
26 | | - $this->messagePack = class_exists(Packer::class); |
27 | | - $this->igBinary = class_exists('igbinary_serialize'); |
28 | | - } |
29 | | - |
30 | | - /** |
31 | | - * @param array<string> $tags |
32 | | - * @throws Exception |
33 | | - * @throws InvalidDataException |
34 | | - */ |
35 | | - public function set($entryIdentifier, $variable, array $tags = [], $lifetime = null): void |
36 | | - { |
37 | | - if (!$this->isValidEntryIdentifier($entryIdentifier)) { |
38 | | - throw new \InvalidArgumentException( |
39 | | - '"' . $entryIdentifier . '" is not a valid cache entry identifier.', |
40 | | - 1233058264 |
41 | | - ); |
42 | | - } |
43 | | - |
44 | | - foreach ($tags as $tag) { |
45 | | - if (!$this->isValidTag($tag)) { |
46 | | - throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058269); |
47 | | - } |
48 | | - } |
49 | | - |
50 | | - foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_variablefrontend.php']['set'] ?? [] as $_funcRef) { |
51 | | - $params = [ |
52 | | - 'entryIdentifier' => &$entryIdentifier, |
53 | | - 'variable' => &$variable, |
54 | | - 'tags' => &$tags, |
55 | | - 'lifetime' => &$lifetime, |
56 | | - ]; |
57 | | - GeneralUtility::callUserFunction($_funcRef, $params, $this); |
58 | | - } |
59 | | - |
60 | | - if (!$this->backend instanceof TransientBackendInterface) { |
61 | | - $variable = $this->serialize($variable); |
62 | | - if (null === $variable) { |
63 | | - throw new \RuntimeException('Could not serialize variable for cache'); |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - $this->backend->set($entryIdentifier, $variable, $tags, $lifetime); |
68 | | - } |
69 | | - |
70 | | - /** |
71 | | - * Finds and returns a variable value from the cache. |
72 | | - * |
73 | | - * @param string $entryIdentifier Identifier of the cache entry to fetch |
74 | | - * |
75 | | - * @return mixed The value |
76 | | - * @throws \InvalidArgumentException if the identifier is not valid |
77 | | - */ |
78 | | - public function get($entryIdentifier) |
79 | | - { |
80 | | - if (!$this->isValidEntryIdentifier($entryIdentifier)) { |
81 | | - throw new \InvalidArgumentException( |
82 | | - '"' . $entryIdentifier . '" is not a valid cache entry identifier.', |
83 | | - 1233058294 |
84 | | - ); |
85 | | - } |
86 | | - |
87 | | - $rawResult = $this->backend->get($entryIdentifier); |
88 | | - if ($rawResult === false) { |
89 | | - return false; |
90 | | - } |
91 | | - |
92 | | - return $this->backend instanceof TransientBackendInterface ? $rawResult : $this->unserialize($rawResult); |
93 | | - } |
94 | | - |
95 | | - protected function serialize(mixed $variable): ?string |
96 | | - { |
97 | | - if ($this->igBinary) { |
98 | | - return igbinary_serialize($variable); |
99 | | - } |
100 | | - |
101 | | - if ($this->messagePack) { |
102 | | - $packer = GeneralUtility::makeInstance(Packer::class, null, [ |
103 | | - new PageTransformer(10), |
104 | | - new UriTransformer(11), |
105 | | - ]); |
106 | | - assert($packer instanceof Packer); |
107 | | - return $packer->pack($variable); |
108 | | - } |
109 | | - |
110 | | - return serialize($variable); |
111 | | - } |
112 | | - |
113 | | - protected function unserialize(string $rawResult): mixed |
114 | | - { |
115 | | - if ($this->igBinary) { |
116 | | - return igbinary_unserialize($rawResult); |
117 | | - } |
118 | | - |
119 | | - if ($this->messagePack) { |
120 | | - $unpacker = GeneralUtility::makeInstance(BufferUnpacker::class, $rawResult, null, [ |
121 | | - new PageTransformer(10), |
122 | | - new UriTransformer(11), |
123 | | - ]); |
124 | | - assert($unpacker instanceof BufferUnpacker); |
125 | | - return $unpacker->unpack(); |
126 | | - } |
127 | | - |
128 | | - return unserialize($rawResult); |
| 16 | + trigger_deprecation('weakbit/lucene-cache', '2.0.3', 'The class %s is deprecated and will be removed in a future version.', self::class); |
129 | 17 | } |
130 | 18 | } |
0 commit comments