Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Helper.php
Go to the documentation of this file.
1 <?php
7 
9 use RecursiveDirectoryIterator;
10 use RecursiveIteratorIterator;
11 
17 class Helper
18 {
25  const INFO_WRITABLE = 1;
26 
33  const INFO_READABLE = 2;
34 
41  const INFO_SIZE = 4;
42 
49  const INFO_ALL = 7;
50 
61  public function rm($path, $skipPaths = [], $removeRoot = false)
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  }
78 
89  public function getInfo($path, $infoOptions = self::INFO_ALL, $skipFiles = [])
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  }
135 }
rm($path, $skipPaths=[], $removeRoot=false)
Definition: Helper.php:61
getInfo($path, $infoOptions=self::INFO_ALL, $skipFiles=[])
Definition: Helper.php:89
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52