1 | <?php |
||
33 | class CacheManager { |
||
34 | |||
35 | /** |
||
36 | * @var boolean |
||
37 | */ |
||
38 | protected static $useCache; |
||
39 | |||
40 | /** |
||
41 | * @var boolean |
||
42 | */ |
||
43 | protected static $enableCache = TRUE; |
||
44 | |||
45 | /** |
||
46 | * @var CacheManager |
||
47 | */ |
||
48 | protected static $instance; |
||
49 | |||
50 | /** |
||
51 | * @var array |
||
52 | */ |
||
53 | protected static $confArray = array(); |
||
54 | |||
55 | /** |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $cache = array(); |
||
59 | |||
60 | /** |
||
61 | * Class constructor |
||
62 | * |
||
63 | * @return void |
||
|
|||
64 | */ |
||
65 | 20 | protected function __construct() { |
|
66 | 20 | if (!isset(self::$useCache)) { |
|
67 | 20 | self::$useCache = FALSE; |
|
68 | |||
69 | 20 | if (empty(self::$confArray)) { |
|
70 | 20 | self::$confArray = @unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['languagevisibility']); |
|
71 | 20 | } |
|
72 | |||
73 | 20 | if (is_array(self::$confArray) && self::$confArray['useCache']) { |
|
74 | self::$useCache = (1 === (int)self::$confArray['useCache']); |
||
75 | } |
||
76 | 20 | } |
|
77 | 20 | } |
|
78 | |||
79 | /** |
||
80 | * Method to determine if preCaching should be used or not. |
||
81 | * |
||
82 | * @return boolean |
||
83 | */ |
||
84 | 20 | public static function isCacheEnabled() { |
|
87 | |||
88 | /** |
||
89 | * Use this method to force the cache usage. |
||
90 | * |
||
91 | * @return void |
||
92 | */ |
||
93 | public static function enableCache() { |
||
94 | self::$enableCache = TRUE; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Use this method to unforce the cache usage. |
||
99 | * |
||
100 | * @return void |
||
101 | */ |
||
102 | public static function disableCache() { |
||
103 | self::$enableCache = FALSE; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Flushed all caches. |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | public function flushAllCaches() { |
||
112 | $this->cache = array(); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Returns the cache array for a given name space. |
||
117 | * |
||
118 | * @param $namespace |
||
119 | * @return array |
||
120 | */ |
||
121 | 20 | public function get($namespace) { |
|
122 | 20 | if (array_key_exists($namespace, $this->cache) && self::isCacheEnabled()) { |
|
123 | return $this->cache[$namespace]; |
||
124 | } else { |
||
125 | 20 | return array(); |
|
126 | } |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Method to write content into the cache. |
||
131 | * |
||
132 | * @param $namespace |
||
133 | * @param $content |
||
134 | * @return void |
||
135 | */ |
||
136 | 20 | public function set($namespace, $content) { |
|
139 | |||
140 | /** |
||
141 | * Returns an instance of the cacheManager singleton. |
||
142 | * |
||
143 | * @return CacheManager |
||
144 | */ |
||
145 | 20 | public static function getInstance() { |
|
152 | |||
153 | /** |
||
154 | * Prevent from cloning |
||
155 | * |
||
156 | * @param void |
||
157 | * @return void |
||
158 | */ |
||
159 | public final function __clone() { |
||
162 | } |
||
163 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.