Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Static Public Member Functions
Dirs Class Reference

Static Public Member Functions

static rm ($dirname)
 
static mkdirStrict ($path, $recursive=true, $mode=0777)
 
static copyFileStrict ($source, $dest)
 

Detailed Description

Definition at line 8 of file Dirs.php.

Member Function Documentation

◆ copyFileStrict()

static copyFileStrict (   $source,
  $dest 
)
static
Parameters
string$source
string$dest
Returns
void
Exceptions

Definition at line 99 of file Dirs.php.

100  {
101  $exists = file_exists($source);
102  if (!$exists) {
103  throw new \Exception('No file exists: ' . $exists);
104  }
105  }
$source
Definition: source.php:23

◆ mkdirStrict()

static mkdirStrict (   $path,
  $recursive = true,
  $mode = 0777 
)
static

Attempts to create the directory

Parameters
string$path
bool$recursive
int$mode
Returns
true
Exceptions

Definition at line 76 of file Dirs.php.

77  {
78  $exists = file_exists($path);
79  if ($exists && is_dir($path)) {
80  return true;
81  }
82  if ($exists && !is_dir($path)) {
83  throw new \Exception("'{$path}' already exists, should be a dir, not a file!");
84  }
85  $out = @mkdir($path, $mode, $recursive);
86  if (false === $out) {
87  throw new \Exception("Can't create dir: '{$path}'");
88  }
89  return true;
90  }
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
mkdir($pathname, $mode=0777, $recursive=false, $context=null)
Definition: ioMock.php:25

◆ rm()

static rm (   $dirname)
static
Parameters
string[]|string$dirname
Returns
bool @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity) @SuppressWarnings(PHPMD.ShortMethodName)

Definition at line 17 of file Dirs.php.

18  {
19  if (is_array($dirname)) {
20  $dirname = $dirname[1];
21  }
22  // Sanity check
23  if (!@file_exists($dirname)) {
24  return false;
25  }
26 
27  // Simple delete for a file
28  if (@is_file($dirname) || @is_link($dirname)) {
29  return unlink($dirname);
30  }
31 
32  // Create and iterate stack
33  $stack = [$dirname];
34  while ($entry = array_pop($stack)) {
35  // Watch for symlinks
36  if (@is_link($entry)) {
37  @unlink($entry);
38  continue;
39  }
40 
41  // Attempt to remove the directory
42  if (@rmdir($entry)) {
43  continue;
44  }
45 
46  // Otherwise add it to the stack
47  $stack[] = $entry;
48  $dh = opendir($entry);
49  while (false !== ($child = readdir($dh))) {
50  // Ignore pointers
51  if ($child === '.' || $child === '..') {
52  continue;
53  }
54  // Unlink files and add directories to stack
55  $child = $entry . '/' . $child;
56  if (is_dir($child) && !is_link($child)) {
57  $stack[] = $child;
58  } else {
59  @unlink($child);
60  }
61  }
62  @closedir($dh);
63  }
64  return true;
65  }

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