[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Cache / Frontend / PhpFrontend.php
1 <?php
2 namespace TYPO3\CMS\Core\Cache\Frontend;
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 * A cache frontend tailored to PHP code.
18 *
19 * This file is a backport from FLOW3
20 *
21 * @author Robert Lemke <robert@typo3.org>
22 * @api
23 */
24 class PhpFrontend extends \TYPO3\CMS\Core\Cache\Frontend\StringFrontend {
25
26 /**
27 * Constructs the cache
28 *
29 * @param string $identifier A identifier which describes this cache
30 * @param \TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface $backend Backend to be used for this cache
31 */
32 public function __construct($identifier, \TYPO3\CMS\Core\Cache\Backend\PhpCapableBackendInterface $backend) {
33 parent::__construct($identifier, $backend);
34 }
35
36 /**
37 * Saves the PHP source code in the cache.
38 *
39 * @param string $entryIdentifier An identifier used for this cache entry, for example the class name
40 * @param string $sourceCode PHP source code
41 * @param array $tags Tags to associate with this cache entry
42 * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
43 * @return void
44 * @throws \InvalidArgumentException If $entryIdentifier or $tags is invalid
45 * @throws \TYPO3\CMS\Core\Cache\Exception\InvalidDataException If $sourceCode is not a string
46 * @api
47 */
48 public function set($entryIdentifier, $sourceCode, array $tags = array(), $lifetime = NULL) {
49 if (!$this->isValidEntryIdentifier($entryIdentifier)) {
50 throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1264023823);
51 }
52 if (!is_string($sourceCode)) {
53 throw new \TYPO3\CMS\Core\Cache\Exception\InvalidDataException('The given source code is not a valid string.', 1264023824);
54 }
55 foreach ($tags as $tag) {
56 if (!$this->isValidTag($tag)) {
57 throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1264023825);
58 }
59 }
60 $sourceCode = '<?php' . chr(10) . $sourceCode . chr(10) . '#';
61 $this->backend->set($entryIdentifier, $sourceCode, $tags, $lifetime);
62 }
63
64 /**
65 * Loads PHP code from the cache and require_onces it right away.
66 *
67 * @param string $entryIdentifier An identifier which describes the cache entry to load
68 * @return mixed Potential return value from the include operation
69 * @api
70 */
71 public function requireOnce($entryIdentifier) {
72 return $this->backend->requireOnce($entryIdentifier);
73 }
74
75 }