TYPO3 CMS  TYPO3_8-7
StringFrontend.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 
18 
26 {
38  public function set($entryIdentifier, $string, array $tags = [], $lifetime = null)
39  {
40  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
41  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233057566);
42  }
43  if (!is_string($string)) {
44  throw new InvalidDataException('Given data is of type "' . gettype($string) . '", but a string is expected for string cache.', 1222808333);
45  }
46  foreach ($tags as $tag) {
47  if (!$this->isValidTag($tag)) {
48  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057512);
49  }
50  }
51  $this->backend->set($entryIdentifier, $string, $tags, $lifetime);
52  }
53 
62  public function get($entryIdentifier)
63  {
64  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
65  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233057752);
66  }
67  return $this->backend->get($entryIdentifier);
68  }
69 
78  public function getByTag($tag)
79  {
80  if (!$this->isValidTag($tag)) {
81  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233057772);
82  }
83  $entries = [];
84  $identifiers = $this->backend->findIdentifiersByTag($tag);
85  foreach ($identifiers as $identifier) {
86  $entries[] = $this->backend->get($identifier);
87  }
88  return $entries;
89  }
90 }