class PirateDayCacheContext in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/config/tests/config_override_test/src/Cache/PirateDayCacheContext.php \Drupal\config_override_test\Cache\PirateDayCacheContext
Defines the PirateDayCacheContext service that allows to cache the booty.
Cache context ID: 'pirate_day'.
Hierarchy
- class \Drupal\config_override_test\Cache\PirateDayCacheContext implements CacheContextInterface
Expanded class hierarchy of PirateDayCacheContext
2 files declare their use of PirateDayCacheContext
- CacheabilityMetadataConfigOverrideTest.php in core/
modules/ config/ src/ Tests/ CacheabilityMetadataConfigOverrideTest.php - Contains \Drupal\config\Tests\CacheabilityMetadataConfigOverrideTest.
- PirateDayCacheabilityMetadataConfigOverride.php in core/
modules/ config/ tests/ config_override_test/ src/ PirateDayCacheabilityMetadataConfigOverride.php - Contains \Drupal\config_override_test\PirateDayCacheabilityMetadataConfigOverride.
1 string reference to 'PirateDayCacheContext'
- config_override_test.services.yml in core/
modules/ config/ tests/ config_override_test/ config_override_test.services.yml - core/modules/config/tests/config_override_test/config_override_test.services.yml
1 service uses PirateDayCacheContext
- cache_context.pirate_day in core/
modules/ config/ tests/ config_override_test/ config_override_test.services.yml - Drupal\config_override_test\Cache\PirateDayCacheContext
File
- core/
modules/ config/ tests/ config_override_test/ src/ Cache/ PirateDayCacheContext.php, line 18 - Contains \Drupal\config_override_test\Cache\PirateDayCacheContext.
Namespace
Drupal\config_override_test\CacheView source
class PirateDayCacheContext implements CacheContextInterface {
/**
* The length of Pirate Day. It lasts 24 hours.
*
* This is a simplified test implementation. In a real life Pirate Day module
* this data wouldn't be defined in a constant, but calculated in a static
* method. If it were Pirate Day it should return the number of seconds until
* midnight, and on all other days it should return the number of seconds
* until the start of the next Pirate Day.
*/
const PIRATE_DAY_MAX_AGE = 86400;
/**
* {@inheritdoc}
*/
public static function getLabel() {
return t('Pirate day');
}
/**
* {@inheritdoc}
*/
public function getContext() {
$is_pirate_day = static::isPirateDay() ? 'yarr' : 'nay';
return "pirate_day." . $is_pirate_day;
}
/**
* Returns whether or not it is Pirate Day.
*
* To ease testing this is determined with a global variable rather than using
* the traditional compass and sextant.
*
* @return bool
* Returns TRUE if it is Pirate Day today.
*/
public static function isPirateDay() {
return !empty($GLOBALS['it_is_pirate_day']);
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PirateDayCacheContext:: |
public | function |
Gets the cacheability metadata for the context. Overrides CacheContextInterface:: |
|
PirateDayCacheContext:: |
public | function |
Returns the string representation of the cache context. Overrides CacheContextInterface:: |
|
PirateDayCacheContext:: |
public static | function |
Returns the label of the cache context. Overrides CacheContextInterface:: |
|
PirateDayCacheContext:: |
public static | function | Returns whether or not it is Pirate Day. | |
PirateDayCacheContext:: |
constant | The length of Pirate Day. It lasts 24 hours. |