Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
State.php
Go to the documentation of this file.
1 <?php
9 
13 
14 class State implements StateInterface
15 {
19  const PARAM_BAN_CACHE = 'global_ban_use_cache';
20 
24  const CACHE_KEY = 'cache_types';
25 
31  private $config;
32 
38  private $writer;
39 
45  private $statuses;
46 
52  private $banAll;
53 
61  public function __construct(DeploymentConfig $config, Writer $writer, $banAll = false)
62  {
63  $this->config = $config;
64  $this->writer = $writer;
65  $this->banAll = $banAll;
66  }
67 
74  public function isEnabled($cacheType)
75  {
76  $this->load();
77  return isset($this->statuses[$cacheType]) ? (bool)$this->statuses[$cacheType] : false;
78  }
79 
87  public function setEnabled($cacheType, $isEnabled)
88  {
89  $this->load();
90  $this->statuses[$cacheType] = (int)$isEnabled;
91  }
92 
98  public function persist()
99  {
100  $this->load();
101  $this->writer->saveConfig([ConfigFilePool::APP_ENV => [self::CACHE_KEY => $this->statuses]]);
102  }
103 
109  private function load()
110  {
111  if (null === $this->statuses) {
112  $this->statuses = [];
113  if ($this->banAll) {
114  return;
115  }
116  $this->statuses = $this->config->getConfigData(self::CACHE_KEY) ?: [];
117  }
118  }
119 }
$config
Definition: fraud_order.php:17
__construct(DeploymentConfig $config, Writer $writer, $banAll=false)
Definition: State.php:61
setEnabled($cacheType, $isEnabled)
Definition: State.php:87