TYPO3  7.6
VariableFrontend.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 
18 
26 {
33  protected $useIgBinary = false;
34 
40  public function initializeObject()
41  {
42  $this->useIgBinary = extension_loaded('igbinary');
43  }
44 
57  public function set($entryIdentifier, $variable, array $tags = array(), $lifetime = null)
58  {
59  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
60  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058264);
61  }
62  foreach ($tags as $tag) {
63  if (!$this->isValidTag($tag)) {
64  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058269);
65  }
66  }
67  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_variablefrontend.php']['set'])) {
68  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_cache_frontend_variablefrontend.php']['set'] as $_funcRef) {
69  $params = array(
70  'entryIdentifier' => &$entryIdentifier,
71  'variable' => &$variable,
72  'tags' => &$tags,
73  'lifetime' => &$lifetime
74  );
75  GeneralUtility::callUserFunction($_funcRef, $params, $this);
76  }
77  }
78  if ($this->useIgBinary === true) {
79  $this->backend->set($entryIdentifier, igbinary_serialize($variable), $tags, $lifetime);
80  } else {
81  $this->backend->set($entryIdentifier, serialize($variable), $tags, $lifetime);
82  }
83  }
84 
93  public function get($entryIdentifier)
94  {
95  if (!$this->isValidEntryIdentifier($entryIdentifier)) {
96  throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1233058294);
97  }
98  $rawResult = $this->backend->get($entryIdentifier);
99  if ($rawResult === false) {
100  return false;
101  } else {
102  return $this->useIgBinary === true ? igbinary_unserialize($rawResult) : unserialize($rawResult);
103  }
104  }
105 
114  public function getByTag($tag)
115  {
116  if (!$this->isValidTag($tag)) {
117  throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1233058312);
118  }
119  $entries = array();
120  $identifiers = $this->backend->findIdentifiersByTag($tag);
121  foreach ($identifiers as $identifier) {
122  $rawResult = $this->backend->get($identifier);
123  if ($rawResult !== false) {
124  $entries[] = $this->useIgBinary === true ? igbinary_unserialize($rawResult) : unserialize($rawResult);
125  }
126  }
127  return $entries;
128  }
129 }