2 /***************************************************************
5 * (c) 2010 Christian Kuhn <lolli@schwarzbu.ch>
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.
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
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.
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
27 * A cache frontend tailored to PHP code.
29 * This file is a backport from FLOW3
32 * @subpackage t3lib_cache
37 class t3lib_cache_frontend_PhpFrontend
extends t3lib_cache_frontend_StringFrontend
{
39 * Constructs the cache
41 * @param string $identifier A identifier which describes this cache
42 * @param t3lib_cache_backend_PhpCapableBackend $backend Backend to be used for this cache
43 * @author Robert Lemke <robert@typo3.org>
45 public function __construct($identifier, t3lib_cache_backend_PhpCapableBackend
$backend) {
46 parent
::__construct($identifier, $backend);
50 * Saves the PHP source code in the cache.
52 * @param string $entryIdentifier An identifier used for this cache entry, for example the class name
53 * @param string $sourceCode PHP source code
54 * @param array $tags Tags to associate with this cache entry
55 * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
57 * @author Robert Lemke <robert@typo3.org>
60 public function set($entryIdentifier, $sourceCode, $tags = array(), $lifetime = NULL) {
61 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
62 throw new InvalidArgumentException(
63 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
67 if (!is_string($sourceCode)) {
68 throw new t3lib_cache_exception_InvalidData(
69 'The given source code is not a valid string.',
73 foreach ($tags as $tag) {
74 if (!$this->isValidTag($tag)) {
75 throw new InvalidArgumentException(
76 '"' . $tag . '" is not a valid tag for a cache entry.',
81 $sourceCode = '<?php' . chr(10) . $sourceCode . chr(10) . '__halt_compiler();';
82 $this->backend
->set($entryIdentifier, $sourceCode, $tags, $lifetime);
86 * Loads PHP code from the cache and require_onces it right away.
88 * @param string $entryIdentifier An identifier which describes the cache entry to load
89 * @return mixed Potential return value from the include operation
90 * @author Robert Lemke <robert@typo3.org>
93 public function requireOnce($entryIdentifier) {
94 return $this->backend
->requireOnce($entryIdentifier);
98 if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/cache/class.t3lib_cache_frontend_phpfrontend.php']) {
99 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE
]['XCLASS']['t3lib/cache/class.t3lib_cache_frontend_phpfrontend.php']);