TimeZoneCacheContext.php 777 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace Drupal\Core\Cache\Context;
  3. use Drupal\Core\Cache\CacheableMetadata;
  4. /**
  5. * Defines the TimeZoneCacheContext service, for "per time zone" caching.
  6. *
  7. * Cache context ID: 'timezone'.
  8. *
  9. * @see \Drupal\Core\Session\AccountProxy::setAccount()
  10. */
  11. class TimeZoneCacheContext implements CacheContextInterface {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public static function getLabel() {
  16. return t("Time zone");
  17. }
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public function getContext() {
  22. // date_default_timezone_set() is called in AccountProxy::setAccount(), so
  23. // we can safely retrieve the timezone.
  24. return date_default_timezone_get();
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function getCacheableMetadata() {
  30. return new CacheableMetadata();
  31. }
  32. }