Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
framework
App
State
CleanupFiles.php
Go to the documentation of this file.
1
<?php
7
namespace
Magento\Framework\App\State
;
8
9
use
Magento\Framework\Filesystem
;
10
use
Magento\Framework\Exception\FileSystemException
;
11
use
Magento\Framework\App\Filesystem\DirectoryList
;
12
16
class
CleanupFiles
17
{
23
private
$filesystem;
24
30
public
function
__construct
(
Filesystem
$filesystem)
31
{
32
$this->filesystem =
$filesystem
;
33
}
34
40
public
function
clearCodeGeneratedFiles
()
41
{
42
return
array_merge(
43
$this->
clearCodeGeneratedClasses
(),
44
$this->
clearMaterializedViewFiles
()
45
);
46
}
47
53
public
function
clearCodeGeneratedClasses
()
54
{
55
return
array_merge(
56
$this->emptyDir(
DirectoryList::GENERATED_CODE
),
57
$this->emptyDir(
DirectoryList::GENERATED_METADATA
)
58
);
59
}
60
66
public
function
clearMaterializedViewFiles
()
67
{
68
return
array_merge(
69
$this->emptyDir(
DirectoryList::STATIC_VIEW
),
70
$this->emptyDir(
DirectoryList::VAR_DIR
,
DirectoryList::TMP_MATERIALIZATION_DIR
)
71
);
72
}
73
79
public
function
clearAllFiles
()
80
{
81
return
array_merge(
82
$this->emptyDir(
DirectoryList::STATIC_VIEW
),
83
$this->emptyDir(
DirectoryList::VAR_DIR
)
84
);
85
}
86
94
private
function
emptyDir(
$code
, $subPath =
null
)
95
{
96
$messages = [];
97
98
$dir = $this->filesystem->getDirectoryWrite(
$code
);
99
$dirPath
= $dir->getAbsolutePath();
100
if
(!$dir->isExist()) {
101
$messages[] =
"The directory '{$dirPath}' doesn't exist - skipping cleanup"
;
102
return
$messages;
103
}
104
foreach
($dir->search(
'*'
, $subPath) as
$path
) {
105
if
(
$path
!==
'.'
&&
$path
!==
'..'
) {
106
$messages[] =
$dirPath
.
$path
;
107
try
{
108
$dir->delete(
$path
);
109
}
catch
(FileSystemException $e) {
110
$messages[] = $e->getMessage();
111
}
112
}
113
}
114
115
return
$messages;
116
}
117
}
Magento\Framework\App\Filesystem\DirectoryList\STATIC_VIEW
const STATIC_VIEW
Definition:
DirectoryList.php:53
Magento\Framework\Filesystem
Definition:
Filesystem.php:16
Magento\Framework\App\Filesystem\DirectoryList\GENERATED_CODE
const GENERATED_CODE
Definition:
DirectoryList.php:131
Magento\Framework\Filesystem
Magento\Framework\App\Filesystem\DirectoryList\VAR_DIR
const VAR_DIR
Definition:
DirectoryList.php:58
Magento\Framework\App\Filesystem\DirectoryList\TMP_MATERIALIZATION_DIR
const TMP_MATERIALIZATION_DIR
Definition:
DirectoryList.php:115
Magento\Framework\Exception\FileSystemException
Definition:
FileSystemException.php:14
Magento\Framework\App\State\CleanupFiles\clearMaterializedViewFiles
clearMaterializedViewFiles()
Definition:
CleanupFiles.php:66
Magento\Framework\App\State\CleanupFiles\__construct
__construct(Filesystem $filesystem)
Definition:
CleanupFiles.php:30
Magento\Framework\App\State\CleanupFiles
Definition:
CleanupFiles.php:16
Magento\Framework\App\State\CleanupFiles\clearAllFiles
clearAllFiles()
Definition:
CleanupFiles.php:79
Magento\Framework\App\State\CleanupFiles\clearCodeGeneratedClasses
clearCodeGeneratedClasses()
Definition:
CleanupFiles.php:53
Magento\Framework\App\State
Definition:
CleanupFiles.php:7
$dirPath
$dirPath
Definition:
import_with_filesystem_images.php:18
Magento\Framework\App\Filesystem\DirectoryList\GENERATED_METADATA
const GENERATED_METADATA
Definition:
DirectoryList.php:136
Magento\Framework\App\Filesystem\DirectoryList
Definition:
DirectoryList.php:13
$filesystem
$filesystem
Definition:
validate_image.php:10
Magento\Framework\App\State\CleanupFiles\clearCodeGeneratedFiles
clearCodeGeneratedFiles()
Definition:
CleanupFiles.php:40
$path
$path
Definition:
import_with_filesystem_images.php:14
$code
$code
Definition:
info.phtml:12