vendor/sensio/framework-extra-bundle/src/Configuration/Cache.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sensio\Bundle\FrameworkExtraBundle\Configuration;
  11. /**
  12. * The Cache class handles the Cache annotation parts.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. * @Annotation
  16. */
  17. class Cache extends ConfigurationAnnotation
  18. {
  19. /**
  20. * The expiration date as a valid date for the strtotime() function.
  21. *
  22. * @var string
  23. */
  24. private $expires;
  25. /**
  26. * The number of seconds that the response is considered fresh by a private
  27. * cache like a web browser.
  28. *
  29. * @var int
  30. */
  31. private $maxage;
  32. /**
  33. * The number of seconds that the response is considered fresh by a public
  34. * cache like a reverse proxy cache.
  35. *
  36. * @var int
  37. */
  38. private $smaxage;
  39. /**
  40. * Whether the response is public or not.
  41. *
  42. * @var bool
  43. */
  44. private $public;
  45. /**
  46. * Whether or not the response must be revalidated.
  47. *
  48. * @var bool
  49. */
  50. private $mustRevalidate;
  51. /**
  52. * Additional "Vary:"-headers.
  53. *
  54. * @var array
  55. */
  56. private $vary;
  57. /**
  58. * An expression to compute the Last-Modified HTTP header.
  59. *
  60. * @var string
  61. */
  62. private $lastModified;
  63. /**
  64. * An expression to compute the ETag HTTP header.
  65. *
  66. * @var string
  67. */
  68. private $etag;
  69. /**
  70. * max-stale Cache-Control header
  71. * It can be expressed in seconds or with a relative time format (1 day, 2 weeks, ...).
  72. *
  73. * @var int|string
  74. */
  75. private $maxStale;
  76. /**
  77. * stale-while-revalidate Cache-Control header
  78. * It can be expressed in seconds or with a relative time format (1 day, 2 weeks, ...).
  79. *
  80. * @var int|string
  81. */
  82. private $staleWhileRevalidate;
  83. /**
  84. * stale-if-error Cache-Control header
  85. * It can be expressed in seconds or with a relative time format (1 day, 2 weeks, ...).
  86. *
  87. * @var int|string
  88. */
  89. private $staleIfError;
  90. /**
  91. * Returns the expiration date for the Expires header field.
  92. *
  93. * @return string
  94. */
  95. public function getExpires()
  96. {
  97. return $this->expires;
  98. }
  99. /**
  100. * Sets the expiration date for the Expires header field.
  101. *
  102. * @param string $expires A valid php date
  103. */
  104. public function setExpires($expires)
  105. {
  106. $this->expires = $expires;
  107. }
  108. /**
  109. * Sets the number of seconds for the max-age cache-control header field.
  110. *
  111. * @param int $maxage A number of seconds
  112. */
  113. public function setMaxAge($maxage)
  114. {
  115. $this->maxage = $maxage;
  116. }
  117. /**
  118. * Returns the number of seconds the response is considered fresh by a
  119. * private cache.
  120. *
  121. * @return int
  122. */
  123. public function getMaxAge()
  124. {
  125. return $this->maxage;
  126. }
  127. /**
  128. * Sets the number of seconds for the s-maxage cache-control header field.
  129. *
  130. * @param int $smaxage A number of seconds
  131. */
  132. public function setSMaxAge($smaxage)
  133. {
  134. $this->smaxage = $smaxage;
  135. }
  136. /**
  137. * Returns the number of seconds the response is considered fresh by a
  138. * public cache.
  139. *
  140. * @return int
  141. */
  142. public function getSMaxAge()
  143. {
  144. return $this->smaxage;
  145. }
  146. /**
  147. * Returns whether or not a response is public.
  148. *
  149. * @return bool
  150. */
  151. public function isPublic()
  152. {
  153. return true === $this->public;
  154. }
  155. /**
  156. * @return bool
  157. */
  158. public function mustRevalidate()
  159. {
  160. return true === $this->mustRevalidate;
  161. }
  162. /**
  163. * Forces a response to be revalidated.
  164. *
  165. * @param bool $mustRevalidate
  166. */
  167. public function setMustRevalidate($mustRevalidate)
  168. {
  169. $this->mustRevalidate = (bool) $mustRevalidate;
  170. }
  171. /**
  172. * Returns whether or not a response is private.
  173. *
  174. * @return bool
  175. */
  176. public function isPrivate()
  177. {
  178. return false === $this->public;
  179. }
  180. /**
  181. * Sets a response public.
  182. *
  183. * @param bool $public A boolean value
  184. */
  185. public function setPublic($public)
  186. {
  187. $this->public = (bool) $public;
  188. }
  189. /**
  190. * Returns the custom "Vary"-headers.
  191. *
  192. * @return array
  193. */
  194. public function getVary()
  195. {
  196. return $this->vary;
  197. }
  198. /**
  199. * Add additional "Vary:"-headers.
  200. *
  201. * @param array $vary
  202. */
  203. public function setVary($vary)
  204. {
  205. $this->vary = $vary;
  206. }
  207. /**
  208. * Sets the "Last-Modified"-header expression.
  209. *
  210. * @param string $expression
  211. */
  212. public function setLastModified($expression)
  213. {
  214. $this->lastModified = $expression;
  215. }
  216. /**
  217. * Returns the "Last-Modified"-header expression.
  218. *
  219. * @return string
  220. */
  221. public function getLastModified()
  222. {
  223. return $this->lastModified;
  224. }
  225. /**
  226. * Sets the "ETag"-header expression.
  227. *
  228. * @param string $expression
  229. */
  230. public function setEtag($expression)
  231. {
  232. $this->etag = $expression;
  233. }
  234. /**
  235. * Returns the "ETag"-header expression.
  236. *
  237. * @return string
  238. */
  239. public function getEtag()
  240. {
  241. return $this->etag;
  242. }
  243. /**
  244. * @return int|string
  245. */
  246. public function getMaxStale()
  247. {
  248. return $this->maxStale;
  249. }
  250. /**
  251. * Sets the number of seconds for the max-stale cache-control header field.
  252. *
  253. * @param int|string $maxStale A number of seconds
  254. */
  255. public function setMaxStale($maxStale)
  256. {
  257. $this->maxStale = $maxStale;
  258. }
  259. /**
  260. * @return int|string
  261. */
  262. public function getStaleWhileRevalidate()
  263. {
  264. return $this->staleWhileRevalidate;
  265. }
  266. /**
  267. * @param int|string $staleWhileRevalidate
  268. *
  269. * @return self
  270. */
  271. public function setStaleWhileRevalidate($staleWhileRevalidate)
  272. {
  273. $this->staleWhileRevalidate = $staleWhileRevalidate;
  274. return $this;
  275. }
  276. /**
  277. * @return int|string
  278. */
  279. public function getStaleIfError()
  280. {
  281. return $this->staleIfError;
  282. }
  283. /**
  284. * @param int|string $staleIfError
  285. *
  286. * @return self
  287. */
  288. public function setStaleIfError($staleIfError)
  289. {
  290. $this->staleIfError = $staleIfError;
  291. return $this;
  292. }
  293. /**
  294. * Returns the annotation alias name.
  295. *
  296. * @return string
  297. *
  298. * @see ConfigurationInterface
  299. */
  300. public function getAliasName()
  301. {
  302. return 'cache';
  303. }
  304. /**
  305. * Only one cache directive is allowed.
  306. *
  307. * @return bool
  308. *
  309. * @see ConfigurationInterface
  310. */
  311. public function allowArray()
  312. {
  313. return false;
  314. }
  315. }