[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Cache / Backend / EarlyClassLoaderBackend.php
1 <?php
2 namespace TYPO3\CMS\Core\Cache\Backend;
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
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18
19 /**
20 * A caching backend customized explicitly for the class loader.
21 * This backend is NOT public API
22 *
23 * @internal
24 */
25 class EarlyClassLoaderBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend implements \TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface {
26
27 /**
28 * @var array Holds cache entries
29 */
30 protected $memoryBackend = array();
31
32 /**
33 * Construct this backend
34 */
35 public function __construct() {
36 parent::__construct('production', array());
37 }
38
39 /**
40 * Saves data in the cache.
41 *
42 * @param string $entryIdentifier An identifier for this specific cache entry
43 * @param string $data The data to be stored
44 * @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
45 * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
46 * @return void
47 * @throws \TYPO3\CMS\Core\Cache\Exception if no cache frontend has been set.
48 * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException if the data is not a string
49 * @api
50 */
51 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL) {
52 $this->memoryBackend[$entryIdentifier] = $data;
53 }
54
55 /**
56 * Loads data from the cache.
57 *
58 * @param string $entryIdentifier An identifier which describes the cache entry to load
59 * @return mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded
60 * @api
61 */
62 public function get($entryIdentifier) {
63 return isset($this->memoryBackend[$entryIdentifier]) ? $this->memoryBackend[$entryIdentifier] : FALSE;
64 }
65
66 /**
67 * A method that returns all records
68 *
69 * @return array
70 */
71 public function getAll() {
72 return $this->memoryBackend;
73 }
74
75 /**
76 * Checks if a cache entry with the specified identifier exists.
77 *
78 * @param string $entryIdentifier An identifier specifying the cache entry
79 * @return boolean TRUE if such an entry exists, FALSE if not
80 * @api
81 */
82 public function has($entryIdentifier) {
83 return isset($this->memoryBackend[$entryIdentifier]);
84 }
85
86 /**
87 * Removes all cache entries matching the specified identifier.
88 * Usually this only affects one entry but if - for what reason ever -
89 * old entries for the identifier still exist, they are removed as well.
90 *
91 * @param string $entryIdentifier Specifies the cache entry to remove
92 * @return boolean TRUE if (at least) an entry could be removed or FALSE if no entry was found
93 * @api
94 */
95 public function remove($entryIdentifier) {
96 if (isset($this->memoryBackend[$entryIdentifier])) {
97 unset($this->memoryBackend[$entryIdentifier]);
98 return TRUE;
99 }
100 return FALSE;
101 }
102
103 /**
104 * Removes all cache entries of this cache.
105 *
106 * @return void
107 * @api
108 */
109 public function flush() {
110 $this->memoryBackend = array();
111 }
112
113 /**
114 * Does garbage collection
115 *
116 * @return void
117 * @api
118 */
119 public function collectGarbage() {
120 }
121
122 /**
123 * Loads PHP code from the cache and require_onces it right away.
124 *
125 * @param string $entryIdentifier An identifier which describes the cache entry to load
126 * @return mixed Potential return value from the include operation
127 * @api
128 */
129 public function requireOnce($entryIdentifier) {
130 return isset($this->memoryBackend[$entryIdentifier]) ? require_once ($this->memoryBackend[$entryIdentifier]) : FALSE;
131 }
132
133 /**
134 * Used to set alias for class
135 *
136 * @TODO: Rename method
137 * @param string $entryIdentifier
138 * @param string $filePath
139 * @internal This is not an API method
140 */
141 public function setLinkToPhpFile($entryIdentifier, $filePath) {
142 $this->memoryBackend[$entryIdentifier] = $filePath;
143 }
144
145 }