[FEATURE] Integrate preliminary PackageManager API
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Cache / Backend / EarlyClassLoaderBackend.php
1 <?php
2 namespace TYPO3\CMS\Core\Cache\Backend;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2013 Thomas Maroschik <tmaroschik@dfau.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * A caching backend customized explicitly for the class loader.
34 * This backend is NOT public API
35 *
36 * @internal
37 */
38 class EarlyClassLoaderBackend extends \TYPO3\CMS\Core\Cache\Backend\AbstractBackend implements \TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface {
39
40 /**
41 * @var array Holds cache entries
42 */
43 protected $memoryBackend = array();
44
45 /**
46 * Construct this backend
47 */
48 public function __construct() {
49 parent::__construct('production', array());
50 }
51
52 /**
53 * Saves data in the cache.
54 *
55 * @param string $entryIdentifier An identifier for this specific cache entry
56 * @param string $data The data to be stored
57 * @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
58 * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
59 * @return void
60 * @throws \TYPO3\CMS\Core\Cache\Exception if no cache frontend has been set.
61 * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException if the data is not a string
62 * @api
63 */
64 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL) {
65 $this->memoryBackend[$entryIdentifier] = $data;
66 }
67
68 /**
69 * Loads data from the cache.
70 *
71 * @param string $entryIdentifier An identifier which describes the cache entry to load
72 * @return mixed The cache entry's content as a string or FALSE if the cache entry could not be loaded
73 * @api
74 */
75 public function get($entryIdentifier) {
76 return isset($this->memoryBackend[$entryIdentifier]) ? $this->memoryBackend[$entryIdentifier] : FALSE;
77 }
78
79 /**
80 * A method that returns all records
81 *
82 * @return array
83 */
84 public function getAll() {
85 return $this->memoryBackend;
86 }
87
88 /**
89 * Checks if a cache entry with the specified identifier exists.
90 *
91 * @param string $entryIdentifier An identifier specifying the cache entry
92 * @return boolean TRUE if such an entry exists, FALSE if not
93 * @api
94 */
95 public function has($entryIdentifier) {
96 return isset($this->memoryBackend[$entryIdentifier]);
97 }
98
99 /**
100 * Removes all cache entries matching the specified identifier.
101 * Usually this only affects one entry but if - for what reason ever -
102 * old entries for the identifier still exist, they are removed as well.
103 *
104 * @param string $entryIdentifier Specifies the cache entry to remove
105 * @return boolean TRUE if (at least) an entry could be removed or FALSE if no entry was found
106 * @api
107 */
108 public function remove($entryIdentifier) {
109 if (isset($this->memoryBackend[$entryIdentifier])) {
110 unset($this->memoryBackend[$entryIdentifier]);
111 return TRUE;
112 }
113 return FALSE;
114 }
115
116 /**
117 * Removes all cache entries of this cache.
118 *
119 * @return void
120 * @api
121 */
122 public function flush() {
123 $this->memoryBackend = array();
124 }
125
126 /**
127 * Does garbage collection
128 *
129 * @return void
130 * @api
131 */
132 public function collectGarbage() {
133 }
134
135 /**
136 * Loads PHP code from the cache and require_onces it right away.
137 *
138 * @param string $entryIdentifier An identifier which describes the cache entry to load
139 * @return mixed Potential return value from the include operation
140 * @api
141 */
142 public function requireOnce($entryIdentifier) {
143 return require_once ($this->memoryBackend[$entryIdentifier]);
144 }
145
146 /**
147 * Used to set alias for class
148 *
149 * @TODO: Rename method
150 * @param string $entryIdentifier
151 * @param string $filePath
152 * @internal This is not an API method
153 */
154 public function setLinkToPhpFile($entryIdentifier, $filePath) {
155 $this->memoryBackend[$entryIdentifier] = $filePath;
156 }
157
158 }