Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
Helper Class Reference

Public Member Functions

 rm ($path, $skipPaths=[], $removeRoot=false)
 
 getInfo ($path, $infoOptions=self::INFO_ALL, $skipFiles=[])
 

Data Fields

const INFO_WRITABLE = 1
 
const INFO_READABLE = 2
 
const INFO_SIZE = 4
 
const INFO_ALL = 7
 

Detailed Description

Filesystem helper

Author
Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m

Definition at line 17 of file Helper.php.

Member Function Documentation

◆ getInfo()

getInfo (   $path,
  $infoOptions = self::INFO_ALL,
  $skipFiles = [] 
)

Get information (readable, writable, size) about $path

Parameters
string$path
int$infoOptions
array$skipFiles
Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 89 of file Helper.php.

90  {
91  $info = [];
92  if ($infoOptions & self::INFO_READABLE) {
93  $info['readable'] = true;
94  $info['readableMeta'] = [];
95  }
96 
97  if ($infoOptions & self::INFO_WRITABLE) {
98  $info['writable'] = true;
99  $info['writableMeta'] = [];
100  }
101 
102  if ($infoOptions & self::INFO_SIZE) {
103  $info['size'] = 0;
104  }
105 
106  $filesystemIterator = new RecursiveIteratorIterator(
107  new RecursiveDirectoryIterator($path),
108  RecursiveIteratorIterator::CHILD_FIRST
109  );
110 
111  $iterator = new Filter($filesystemIterator, $skipFiles);
112 
113  foreach ($iterator as $item) {
114  if ($item->isLink()) {
115  continue;
116  }
117 
118  if ($infoOptions & self::INFO_WRITABLE && !$item->isWritable()) {
119  $info['writable'] = false;
120  $info['writableMeta'][] = $item->getPathname();
121  }
122 
123  if ($infoOptions & self::INFO_READABLE && !$item->isReadable()) {
124  $info['readable'] = false;
125  $info['readableMeta'][] = $item->getPathname();
126  }
127 
128  if ($infoOptions & self::INFO_SIZE && !$item->isDir()) {
129  $info['size'] += $item->getSize();
130  }
131  }
132 
133  return $info;
134  }
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52

◆ rm()

rm (   $path,
  $skipPaths = [],
  $removeRoot = false 
)

Recursively delete $path

Parameters
string$path
array$skipPaths
bool$removeRoot
Returns
void
Exceptions

Definition at line 61 of file Helper.php.

62  {
63  $filesystemIterator = new RecursiveIteratorIterator(
64  new RecursiveDirectoryIterator($path),
65  RecursiveIteratorIterator::CHILD_FIRST
66  );
67 
68  $iterator = new Filter($filesystemIterator, $skipPaths);
69 
70  foreach ($iterator as $item) {
71  $item->isDir() ? @rmdir($item->__toString()) : @unlink($item->__toString());
72  }
73 
74  if ($removeRoot && is_dir($path)) {
75  @rmdir($path);
76  }
77  }

Field Documentation

◆ INFO_ALL

const INFO_ALL = 7

Constant can be used in getInfo() function as second parameter. Combination of INFO_WRITABLE, INFO_READABLE, INFO_SIZE

@const int

Definition at line 49 of file Helper.php.

◆ INFO_READABLE

const INFO_READABLE = 2

Constant can be used in getInfo() function as second parameter. Check whether directory and all files/sub directories are readable

@const int

Definition at line 33 of file Helper.php.

◆ INFO_SIZE

const INFO_SIZE = 4

Constant can be used in getInfo() function as second parameter. Get directory size

@const int

Definition at line 41 of file Helper.php.

◆ INFO_WRITABLE

const INFO_WRITABLE = 1

Constant can be used in getInfo() function as second parameter. Check whether directory and all files/sub directories are writable

@const int

Definition at line 25 of file Helper.php.


The documentation for this class was generated from the following file: