PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Classes/TYPO3/FLOW3/Cache/Frontend/PhpFrontend.php

https://github.com/christianjul/FLOW3-Composer
PHP | 66 lines | 20 code | 7 blank | 39 comment | 3 complexity | d79cf044838e9a703105fa19df52841f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-3.0
  1. <?php
  2. namespace TYPO3\FLOW3\Cache\Frontend;
  3. /* *
  4. * This script belongs to the FLOW3 framework. *
  5. * *
  6. * It is free software; you can redistribute it and/or modify it under *
  7. * the terms of the GNU Lesser General Public License, either version 3 *
  8. * of the License, or (at your option) any later version. *
  9. * *
  10. * The TYPO3 project - inspiring people to share! *
  11. * */
  12. /**
  13. * A cache frontend tailored to PHP code.
  14. *
  15. * @api
  16. */
  17. class PhpFrontend extends \TYPO3\FLOW3\Cache\Frontend\StringFrontend {
  18. /**
  19. * Constructs the cache
  20. *
  21. * @param string $identifier A identifier which describes this cache
  22. * @param \TYPO3\FLOW3\Cache\Backend\PhpCapableBackendInterface $backend Backend to be used for this cache
  23. */
  24. public function __construct($identifier, \TYPO3\FLOW3\Cache\Backend\PhpCapableBackendInterface $backend) {
  25. parent::__construct($identifier, $backend);
  26. }
  27. /**
  28. * Saves the PHP source code in the cache.
  29. *
  30. * @param string $entryIdentifier An identifier used for this cache entry, for example the class name
  31. * @param string $sourceCode PHP source code
  32. * @param array $tags Tags to associate with this cache entry
  33. * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited liftime.
  34. * @return void
  35. * @throws \TYPO3\FLOW3\Cache\Exception\InvalidDataException
  36. * @throws \InvalidArgumentException
  37. * @api
  38. */
  39. public function set($entryIdentifier, $sourceCode, array $tags = array(), $lifetime = NULL) {
  40. if (!$this->isValidEntryIdentifier($entryIdentifier)) throw new \InvalidArgumentException('"' . $entryIdentifier . '" is not a valid cache entry identifier.', 1264023823);
  41. if (!is_string($sourceCode)) throw new \TYPO3\FLOW3\Cache\Exception\InvalidDataException('The given source code is not a valid string.', 1264023824);
  42. foreach ($tags as $tag) {
  43. if (!$this->isValidTag($tag)) throw new \InvalidArgumentException('"' . $tag . '" is not a valid tag for a cache entry.', 1264023825);
  44. }
  45. $sourceCode = '<?php' . chr(10) . $sourceCode . chr(10) . '#';
  46. $this->backend->set($entryIdentifier, $sourceCode, $tags, $lifetime);
  47. }
  48. /**
  49. * Loads PHP code from the cache and require_onces it right away.
  50. *
  51. * @param string $entryIdentifier An identifier which describes the cache entry to load
  52. * @return mixed Potential return value from the include operation
  53. * @api
  54. */
  55. public function requireOnce($entryIdentifier) {
  56. return $this->backend->requireOnce($entryIdentifier);
  57. }
  58. }
  59. ?>