[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Cache / Cache.php
1 <?php
2 namespace TYPO3\CMS\Core\Cache;
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 use TYPO3\CMS\Core\Utility\GeneralUtility;
17
18 /**
19 * A cache handling helper class
20 *
21 * @author Ingo Renner <ingo@typo3.org>
22 */
23 class Cache {
24
25 /**
26 * @var boolean TRUE if caching framework was fully initialized
27 */
28 static protected $isCachingFrameworkInitialized = FALSE;
29
30 /**
31 * @var CacheManager
32 */
33 static protected $cacheManager;
34
35 /**
36 * @var CacheFactory
37 */
38 static protected $cacheFactory;
39
40 /**
41 * Initializes the caching framework by loading the cache manager and factory
42 * into the global context.
43 *
44 * @return CacheManager
45 */
46 static public function initializeCachingFramework() {
47 if (!self::isCachingFrameworkInitialized()) {
48 // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
49 self::$cacheManager = new CacheManager();
50 GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', self::$cacheManager);
51 self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
52 // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
53 self::$cacheFactory = new CacheFactory('production', self::$cacheManager);
54 GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', self::$cacheFactory);
55 self::$isCachingFrameworkInitialized = TRUE;
56 }
57 return self::$cacheManager;
58 }
59
60 /**
61 * Determines whether the caching framework is initialized.
62 * The caching framework could be disabled for the core but used by an extension.
63 *
64 * @return boolean True if caching framework is initialized
65 */
66 static public function isCachingFrameworkInitialized() {
67 return self::$isCachingFrameworkInitialized;
68 }
69
70 /**
71 * Resets the isCachingFrameworkInitialized state
72 * Beware! This is not public API and necessary for edge cases in the install tool.
73 *
74 * @return void
75 */
76 static public function flagCachingFrameworkForReinitialization() {
77 self::$isCachingFrameworkInitialized = FALSE;
78 GeneralUtility::removeSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', self::$cacheManager);
79 GeneralUtility::removeSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheFactory', self::$cacheFactory);
80 self::$cacheManager = NULL;
81 self::$cacheFactory = NULL;
82 }
83
84 /**
85 * Helper method for install tool and extension manager to determine
86 * required table structure of all caches that depend on it
87 *
88 * This is not a public API method!
89 *
90 * @return string Required table structure of all registered caches
91 */
92 static public function getDatabaseTableDefinitions() {
93 $tableDefinitions = '';
94 foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
95 $backend = self::$cacheManager->getCache($cacheName)->getBackend();
96 if (method_exists($backend, 'getTableDefinitions')) {
97 $tableDefinitions .= LF . $backend->getTableDefinitions();
98 }
99 }
100 return $tableDefinitions;
101 }
102
103 /**
104 * A slot method to inject the required caching framework database tables to the
105 * tables definitions string
106 *
107 * @param array $sqlString
108 * @param string $extensionKey
109 * @return array
110 */
111 public function addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition(array $sqlString, $extensionKey) {
112 self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
113 $sqlString[] = static::getDatabaseTableDefinitions();
114 return array('sqlString' => $sqlString, 'extensionKey' => $extensionKey);
115 }
116
117 }