Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Cache / Context / PathParentCacheContext.php
1 <?php
2
3 namespace Drupal\Core\Cache\Context;
4
5 use Drupal\Core\Cache\CacheableMetadata;
6
7 /**
8  * Defines a cache context service for path parents.
9  *
10  * Cache context ID: 'url.path.parent'.
11  *
12  * This allows for caching based on the path, excluding everything after the
13  * last forward slash.
14  */
15 class PathParentCacheContext extends RequestStackCacheContextBase implements CacheContextInterface {
16
17   /**
18    * {@inheritdoc}
19    */
20   public static function getLabel() {
21     return t('Parent path');
22   }
23
24   /**
25    * {@inheritdoc}
26    */
27   public function getContext() {
28     $request = $this->requestStack->getCurrentRequest();
29     $path_elements = explode('/', trim($request->getPathInfo(), '/'));
30     array_pop($path_elements);
31     return implode('/', $path_elements);
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public function getCacheableMetadata() {
38     return new CacheableMetadata();
39   }
40
41 }