Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DirSetupUtil.php
Go to the documentation of this file.
1 <?php
8 
9 use FilesystemIterator;
10 use RecursiveDirectoryIterator;
11 
13 {
19  private static $DIR_CONTEXT = [];
20 
27  public static function createGroupDir($fullPath)
28  {
29  //prevent redundant calls to these directories
30  $sanitizedPath = rtrim($fullPath, DIRECTORY_SEPARATOR);
31  // make sure we haven't already cleaned up this directory at any point before deletion
32  if (in_array($sanitizedPath, self::$DIR_CONTEXT)) {
33  return;
34  }
35 
36  if (file_exists($sanitizedPath)) {
37  self::rmDirRecursive($sanitizedPath);
38  }
39 
40  mkdir($sanitizedPath, 0777, true);
41  self::$DIR_CONTEXT[] = $sanitizedPath;
42  }
43 
50  public static function rmdirRecursive($directory)
51  {
52  $it = new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS);
53 
54  while ($it->valid()) {
55  $path = $directory . DIRECTORY_SEPARATOR . $it->getFilename();
56  if ($it->isDir()) {
57  self::rmDirRecursive($path);
58  } else {
59  unlink($path);
60  }
61 
62  $it->next();
63  }
64 
65  rmdir($directory);
66  }
67 }
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
Definition: ioMock.php:25