Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Manager.php
Go to the documentation of this file.
1 <?php
8 
10 
17 class Manager
18 {
24  private $cacheTypeList;
25 
31  private $cacheState;
32 
38  private $pool;
39 
47  public function __construct(
48  TypeListInterface $cacheTypeList,
49  StateInterface $cacheState,
50  Type\FrontendPool $pool
51  ) {
52  $this->cacheTypeList = $cacheTypeList;
53  $this->cacheState = $cacheState;
54  $this->pool = $pool;
55  }
56 
64  public function setEnabled(array $types, $isEnabled)
65  {
66  $changedStatusTypes = [];
67  $isUpdated = false;
68  foreach ($types as $type) {
69  if ($this->cacheState->isEnabled($type) === $isEnabled) { // no need to poke it, if is not going to change
70  continue;
71  }
72  $this->cacheState->setEnabled($type, $isEnabled);
73  $isUpdated = true;
74  $changedStatusTypes[] = $type;
75  }
76  if ($isUpdated) {
77  $this->cacheState->persist();
78  }
79  return $changedStatusTypes;
80  }
81 
88  public function clean(array $types)
89  {
90  foreach ($types as $type) {
91  $this->cacheTypeList->cleanType($type);
92  }
93  }
94 
101  public function flush(array $types)
102  {
103  $flushedBackend = [];
104  foreach ($types as $type) {
105  $backend = $this->pool->get($type)->getBackend();
106  if (in_array($backend, $flushedBackend, true)) { // it was already flushed from another frontend
107  continue;
108  }
109  $backend->clean();
110  $flushedBackend[] = $backend;
111  }
112  }
113 
119  public function getStatus()
120  {
121  $result = [];
122  foreach ($this->cacheTypeList->getTypes() as $type) {
123  $result[$type['id']] = $type['status'];
124  }
125  return $result;
126  }
127 
131  public function getAvailableTypes()
132  {
133  $result = [];
134  foreach ($this->cacheTypeList->getTypes() as $type) {
135  $result[] = $type['id'];
136  }
137  return $result;
138  }
139 }
setEnabled(array $types, $isEnabled)
Definition: Manager.php:64
__construct(TypeListInterface $cacheTypeList, StateInterface $cacheState, Type\FrontendPool $pool)
Definition: Manager.php:47
$type
Definition: item.phtml:13