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.      * Returns the expiration date for the Expires header field.
  78.      *
  79.      * @return string
  80.      */
  81.     public function getExpires()
  82.     {
  83.         return $this->expires;
  84.     }
  85.     /**
  86.      * Sets the expiration date for the Expires header field.
  87.      *
  88.      * @param string $expires A valid php date
  89.      */
  90.     public function setExpires($expires)
  91.     {
  92.         $this->expires $expires;
  93.     }
  94.     /**
  95.      * Sets the number of seconds for the max-age cache-control header field.
  96.      *
  97.      * @param int $maxage A number of seconds
  98.      */
  99.     public function setMaxAge($maxage)
  100.     {
  101.         $this->maxage $maxage;
  102.     }
  103.     /**
  104.      * Returns the number of seconds the response is considered fresh by a
  105.      * private cache.
  106.      *
  107.      * @return int
  108.      */
  109.     public function getMaxAge()
  110.     {
  111.         return $this->maxage;
  112.     }
  113.     /**
  114.      * Sets the number of seconds for the s-maxage cache-control header field.
  115.      *
  116.      * @param int $smaxage A number of seconds
  117.      */
  118.     public function setSMaxAge($smaxage)
  119.     {
  120.         $this->smaxage $smaxage;
  121.     }
  122.     /**
  123.      * Returns the number of seconds the response is considered fresh by a
  124.      * public cache.
  125.      *
  126.      * @return int
  127.      */
  128.     public function getSMaxAge()
  129.     {
  130.         return $this->smaxage;
  131.     }
  132.     /**
  133.      * Returns whether or not a response is public.
  134.      *
  135.      * @return bool
  136.      */
  137.     public function isPublic()
  138.     {
  139.         return true === $this->public;
  140.     }
  141.     /**
  142.      * @return bool
  143.      */
  144.     public function mustRevalidate()
  145.     {
  146.         return true === $this->mustRevalidate;
  147.     }
  148.     /**
  149.      * Forces a response to be revalidated.
  150.      *
  151.      * @param bool $mustRevalidate
  152.      */
  153.     public function setMustRevalidate($mustRevalidate)
  154.     {
  155.         $this->mustRevalidate = (bool) $mustRevalidate;
  156.     }
  157.     /**
  158.      * Returns whether or not a response is private.
  159.      *
  160.      * @return bool
  161.      */
  162.     public function isPrivate()
  163.     {
  164.         return false === $this->public;
  165.     }
  166.     /**
  167.      * Sets a response public.
  168.      *
  169.      * @param bool $public A boolean value
  170.      */
  171.     public function setPublic($public)
  172.     {
  173.         $this->public = (bool) $public;
  174.     }
  175.     /**
  176.      * Returns the custom "Vary"-headers.
  177.      *
  178.      * @return array
  179.      */
  180.     public function getVary()
  181.     {
  182.         return $this->vary;
  183.     }
  184.     /**
  185.      * Add additional "Vary:"-headers.
  186.      *
  187.      * @param array $vary
  188.      */
  189.     public function setVary($vary)
  190.     {
  191.         $this->vary $vary;
  192.     }
  193.     /**
  194.      * Sets the "Last-Modified"-header expression.
  195.      *
  196.      * @param string $expression
  197.      */
  198.     public function setLastModified($expression)
  199.     {
  200.         $this->lastModified $expression;
  201.     }
  202.     /**
  203.      * Returns the "Last-Modified"-header expression.
  204.      *
  205.      * @return string
  206.      */
  207.     public function getLastModified()
  208.     {
  209.         return $this->lastModified;
  210.     }
  211.     /**
  212.      * Sets the "ETag"-header expression.
  213.      *
  214.      * @param string $expression
  215.      */
  216.     public function setEtag($expression)
  217.     {
  218.         $this->etag $expression;
  219.     }
  220.     /**
  221.      * Returns the "ETag"-header expression.
  222.      *
  223.      * @return string
  224.      */
  225.     public function getEtag()
  226.     {
  227.         return $this->etag;
  228.     }
  229.     /**
  230.      * @return int|string
  231.      */
  232.     public function getMaxStale()
  233.     {
  234.         return $this->maxStale;
  235.     }
  236.     /**
  237.      * Sets the number of seconds for the max-stale cache-control header field.
  238.      *
  239.      * @param int|string $maxStale A number of seconds
  240.      */
  241.     public function setMaxStale($maxStale)
  242.     {
  243.         $this->maxStale $maxStale;
  244.     }
  245.     /**
  246.      * Returns the annotation alias name.
  247.      *
  248.      * @return string
  249.      *
  250.      * @see ConfigurationInterface
  251.      */
  252.     public function getAliasName()
  253.     {
  254.         return 'cache';
  255.     }
  256.     /**
  257.      * Only one cache directive is allowed.
  258.      *
  259.      * @return bool
  260.      *
  261.      * @see ConfigurationInterface
  262.      */
  263.     public function allowArray()
  264.     {
  265.         return false;
  266.     }
  267. }