8 use Magento\Framework\App\DeploymentConfig\Writer\PhpFormatter;
27 private $directoryList;
42 $this->directoryList = $directoryList;
43 $this->write = $writeFactory->
create(
BP);
66 if ($this->write->isExist(self::REGENERATE_FLAG)) {
67 $enabledCacheTypes = [];
73 if ($this->write->isExist($this->write->getRelativePath($envPath))) {
74 $enabledCacheTypes = $this->getEnabledCacheTypes();
75 $this->disableAllCacheTypes();
80 $generationPath = $this->write->getRelativePath(
86 if ($this->write->isDirectory($generationPath)) {
87 $this->write->delete($generationPath);
91 if ($this->write->isDirectory($diPath)) {
92 $this->write->delete($diPath);
96 if ($this->write->isDirectory($cachePath)) {
97 $this->write->delete($cachePath);
99 $this->write->delete(self::REGENERATE_FLAG);
100 $this->enableCacheTypes($enabledCacheTypes);
112 $this->write->touch(self::REGENERATE_FLAG);
120 private function getEnabledCacheTypes()
122 $enabledCacheTypes = [];
123 $envPath = $this->getEnvPath();
124 if ($this->write->isReadable($this->write->getRelativePath($envPath))) {
125 $envData = include $envPath;
126 if (isset($envData[
'cache_types'])) {
127 $cacheStatus = $envData[
'cache_types'];
128 $enabledCacheTypes = array_filter($cacheStatus,
function (
$value) {
131 $enabledCacheTypes = array_keys($enabledCacheTypes);
134 return $enabledCacheTypes;
143 private function getEnvPath()
146 $configPool =
new ConfigFilePool();
156 private function disableAllCacheTypes()
158 $envPath = $this->getEnvPath();
159 if ($this->write->isWritable($this->write->getRelativePath($envPath))) {
160 $envData = include $envPath;
162 if (isset($envData[
'cache_types'])) {
163 $cacheTypes = array_keys($envData[
'cache_types']);
165 foreach ($cacheTypes as $cacheType) {
166 $envData[
'cache_types'][$cacheType] = 0;
169 $formatter =
new PhpFormatter();
170 $contents = $formatter->format($envData);
172 $this->write->writeFile($this->write->getRelativePath($envPath),
$contents);
175 $this->write->getAbsolutePath($envPath)
189 private function enableCacheTypes($cacheTypes)
191 if (empty($cacheTypes)) {
194 $envPath = $this->getEnvPath();
195 if ($this->write->isReadable($this->write->getRelativePath($envPath))) {
196 $envData = include $envPath;
197 foreach ($cacheTypes as $cacheType) {
198 if (isset($envData[
'cache_types'][$cacheType])) {
199 $envData[
'cache_types'][$cacheType] = 1;
203 $formatter =
new PhpFormatter();
204 $contents = $formatter->format($envData);
206 $this->write->writeFile($this->write->getRelativePath($envPath),
$contents);
208 opcache_invalidate($this->write->getAbsolutePath($envPath));
create($path, $driverCode=DriverPool::FILE, $createPermissions=null)
__construct(DirectoryList $directoryList, WriteFactory $writeFactory)