Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / config / tests / config_override_test / src / Cache / PirateDayCacheContext.php
1 <?php
2
3 namespace Drupal\config_override_test\Cache;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6 use Drupal\Core\Cache\Context\CacheContextInterface;
7
8 /**
9  * Defines the PirateDayCacheContext service that allows to cache the booty.
10  *
11  * Cache context ID: 'pirate_day'.
12  */
13 class PirateDayCacheContext implements CacheContextInterface {
14
15   /**
16    * The length of Pirate Day. It lasts 24 hours.
17    *
18    * This is a simplified test implementation. In a real life Pirate Day module
19    * this data wouldn't be defined in a constant, but calculated in a static
20    * method. If it were Pirate Day it should return the number of seconds until
21    * midnight, and on all other days it should return the number of seconds
22    * until the start of the next Pirate Day.
23    */
24   const PIRATE_DAY_MAX_AGE = 86400;
25
26   /**
27    * {@inheritdoc}
28    */
29   public static function getLabel() {
30     return t('Pirate day');
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function getContext() {
37     $is_pirate_day = static::isPirateDay() ? 'yarr' : 'nay';
38     return "pirate_day." . $is_pirate_day;
39   }
40
41   /**
42    * Returns whether or not it is Pirate Day.
43    *
44    * To ease testing this is determined with a global variable rather than using
45    * the traditional compass and sextant.
46    *
47    * @return bool
48    *   Returns TRUE if it is Pirate Day today.
49    */
50   public static function isPirateDay() {
51     return !empty($GLOBALS['it_is_pirate_day']);
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   public function getCacheableMetadata() {
58     return new CacheableMetadata();
59   }
60
61 }