Upgraded drupal core with security updates
[yaffs-website] / web / core / lib / Drupal / Core / Cache / ApcuBackendFactory.php
1 <?php
2
3 namespace Drupal\Core\Cache;
4
5 use Drupal\Core\Site\Settings;
6
7 class ApcuBackendFactory implements CacheFactoryInterface {
8
9   /**
10    * The site prefix string.
11    *
12    * @var string
13    */
14   protected $sitePrefix;
15
16   /**
17    * The cache tags checksum provider.
18    *
19    * @var \Drupal\Core\Cache\CacheTagsChecksumInterface
20    */
21   protected $checksumProvider;
22
23   /**
24    * The APCU backend class to use.
25    *
26    * @var string
27    */
28   protected $backendClass;
29
30   /**
31    * Constructs an ApcuBackendFactory object.
32    *
33    * @param string $root
34    *   The app root.
35    * @param string $site_path
36    *   The site path.
37    * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
38    *   The cache tags checksum provider.
39    */
40   public function __construct($root, $site_path, CacheTagsChecksumInterface $checksum_provider) {
41     $this->sitePrefix = Settings::getApcuPrefix('apcu_backend', $root, $site_path);
42     $this->checksumProvider = $checksum_provider;
43     if (version_compare(phpversion('apcu'), '5.0.0', '>=')) {
44       $this->backendClass = 'Drupal\Core\Cache\ApcuBackend';
45     }
46     else {
47       $this->backendClass = 'Drupal\Core\Cache\Apcu4Backend';
48     }
49   }
50
51   /**
52    * Gets ApcuBackend for the specified cache bin.
53    *
54    * @param $bin
55    *   The cache bin for which the object is created.
56    *
57    * @return \Drupal\Core\Cache\ApcuBackend
58    *   The cache backend object for the specified cache bin.
59    */
60   public function get($bin) {
61     return new $this->backendClass($bin, $this->sitePrefix, $this->checksumProvider);
62   }
63
64 }