Fixed bug #10454: t3lib_div::makeInstanceClassName() allows to bypass checks for...
[Packages/TYPO3.CMS.git] / t3lib / cache / class.t3lib_cache_manager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2008 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * The Cache Manager
28 *
29 * This file is a backport from FLOW3
30 *
31 * @package TYPO3
32 * @subpackage t3lib_cache
33 * @version $Id$
34 */
35 class t3lib_cache_Manager implements t3lib_Singleton {
36
37 /**
38 * @const Cache Entry depends on the PHP code of the packages
39 */
40 const TAG_PACKAGES_CODE = '%PACKAGES_CODE';
41
42 /**
43 * @var array Registered Caches
44 */
45 protected $caches = array();
46
47 /**
48 * Registers a cache so it can be retrieved at a later point.
49 *
50 * @param t3lib_cache_AbstractCache The cache to be registered
51 * @return void
52 * @throws t3lib_cache_DuplicateIdentifier if a cache with the given identifier has already been registered.
53 * @author Robert Lemke <robert@typo3.org>
54 */
55 public function registerCache(t3lib_cache_AbstractCache $cache) {
56 $identifier = $cache->getIdentifier();
57
58 if (array_key_exists($identifier, $this->caches)) {
59 throw new t3lib_cache_exception_DuplicateIdentifier(
60 'A cache with identifier "' . $identifier . '" has already been registered.',
61 1203698223
62 );
63 }
64
65 $this->caches[$identifier] = $cache;
66 }
67
68 /**
69 * Returns the cache specified by $identifier
70 *
71 * @param string Identifies which cache to return
72 * @return t3lib_cache_AbstractCache The specified cache
73 * @throws t3lib_cache_Exception_NoSuchCache
74 */
75 public function getCache($identifier) {
76 if (!array_key_exists($identifier, $this->caches)) {
77 throw new t3lib_cache_exception_NoSuchCache(
78 'A cache with identifier "' . $identifier . '" does not exist.',
79 1203699034
80 );
81 }
82
83 return $this->caches[$identifier];
84 }
85
86 /**
87 * Checks if the specified cache has been registered.
88 *
89 * @param string The identifier of the cache
90 * @return boolean TRUE if a cache with the given identifier exists, otherwise FALSE
91 * @author Robert Lemke <robert@typo3.org>
92 */
93 public function hasCache($identifier) {
94 return array_key_exists($identifier, $this->caches);
95 }
96
97 /**
98 * Flushes all registered caches
99 *
100 * @return void
101 * @author Robert Lemke <robert@typo3.org>
102 */
103 public function flushCaches() {
104 foreach ($this->caches as $cache) {
105 $cache->flush();
106 }
107 }
108
109 /**
110 * Flushes entries tagged by the specified tag of all registered
111 * caches.
112 *
113 * @param string Tag to search for
114 * @return void
115 * @author Robert Lemke <robert@typo3.org>
116 */
117 public function flushCachesByTag($tag) {
118 foreach ($this->caches as $cache) {
119 $cache->flushByTag($tag);
120 }
121 }
122 }
123
124
125 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_manager.php']) {
126 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_manager.php']);
127 }
128
129 ?>