TYPO3 API  SVNRelease
class.t3lib_cache_frontend_phpfrontend.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Christian Kuhn <lolli@schwarzbu.ch>
00006  *  All rights reserved
00007  *
00008  *  This script is part of the TYPO3 project. The TYPO3 project is
00009  *  free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  The GNU General Public License can be found at
00015  *  http://www.gnu.org/copyleft/gpl.html.
00016  *
00017  *  This script is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  *  GNU General Public License for more details.
00021  *
00022  *  This copyright notice MUST APPEAR in all copies of the script!
00023  ***************************************************************/
00024 
00025 
00026 /**
00027  * A cache frontend tailored to PHP code.
00028  *
00029  * This file is a backport from FLOW3
00030  *
00031  * @package TYPO3
00032  * @subpackage t3lib_cache
00033  * @api
00034  * @scope prototype
00035  * @version $Id$
00036  */
00037 class t3lib_cache_frontend_PhpFrontend extends t3lib_cache_frontend_StringFrontend {
00038     /**
00039      * Constructs the cache
00040      *
00041      * @param string $identifier A identifier which describes this cache
00042      * @param t3lib_cache_backend_PhpCapableBackend $backend Backend to be used for this cache
00043      * @author Robert Lemke <robert@typo3.org>
00044      */
00045     public function __construct($identifier, t3lib_cache_backend_PhpCapableBackend $backend) {
00046         parent::__construct($identifier, $backend);
00047     }
00048 
00049     /**
00050      * Saves the PHP source code in the cache.
00051      *
00052      * @param string $entryIdentifier An identifier used for this cache entry, for example the class name
00053      * @param string $sourceCode PHP source code
00054      * @param array $tags Tags to associate with this cache entry
00055      * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
00056      * @return void
00057      * @author Robert Lemke <robert@typo3.org>
00058      * @api
00059      */
00060     public function set($entryIdentifier, $sourceCode, $tags = array(), $lifetime = NULL) {
00061         if (!$this->isValidEntryIdentifier($entryIdentifier)) {
00062             throw new InvalidArgumentException(
00063                 '"' . $entryIdentifier . '" is not a valid cache entry identifier.',
00064                 1264023823
00065             );
00066         }
00067         if (!is_string($sourceCode)) {
00068             throw new t3lib_cache_exception_InvalidData(
00069                 'The given source code is not a valid string.',
00070                 1264023824
00071             );
00072         }
00073         foreach ($tags as $tag) {
00074             if (!$this->isValidTag($tag)) {
00075                 throw new InvalidArgumentException(
00076                     '"' . $tag . '" is not a valid tag for a cache entry.',
00077                     1264023825
00078                 );
00079             }
00080         }
00081         $sourceCode = '<?php' . chr(10) . $sourceCode . chr(10) . '#';
00082         $this->backend->set($entryIdentifier, $sourceCode, $tags, $lifetime);
00083     }
00084 
00085     /**
00086      * Loads PHP code from the cache and require_onces it right away.
00087      *
00088      * @param string $entryIdentifier An identifier which describes the cache entry to load
00089      * @return mixed Potential return value from the include operation
00090      * @author Robert Lemke <robert@typo3.org>
00091      * @api
00092      */
00093     public function requireOnce($entryIdentifier) {
00094         return $this->backend->requireOnce($entryIdentifier);
00095     }
00096 }
00097 
00098 if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_frontend_phpfrontend.php']) {
00099     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/cache/class.t3lib_cache_frontend_phpfrontend.php']);
00100 }
00101 
00102 ?>