Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractIo.php
Go to the documentation of this file.
1 <?php
8 
12 abstract class AbstractIo implements IoInterface
13 {
20  protected $_allowCreateFolders = false;
21 
28  public function setAllowCreateFolders($flag)
29  {
30  $this->_allowCreateFolders = (bool)$flag;
31  return $this;
32  }
33 
40  public function open(array $args = [])
41  {
42  return false;
43  }
44 
48  public function dirsep()
49  {
50  return '/';
51  }
52 
58  public function getCleanPath($path)
59  {
60  if (empty($path)) {
61  return './';
62  }
63 
64  $path = trim(preg_replace("/\\\\/", "/", (string)$path));
65 
66  if (!preg_match("/(\.\w{1,4})$/", $path) && !preg_match("/\?[^\\/]+$/", $path) && !preg_match("/\\/$/", $path)
67  ) {
68  $path .= '/';
69  }
70 
71  $matches = [];
72  $pattern = "/^(\\/|\w:\\/|https?:\\/\\/[^\\/]+\\/)?(.*)$/i";
73  preg_match_all($pattern, $path, $matches, PREG_SET_ORDER);
74 
75  $pathTokR = $matches[0][1];
76  $pathTokP = $matches[0][2];
77 
78  $pathTokP = preg_replace(["/^\\/+/", "/\\/+/"], ["", "/"], $pathTokP);
79 
80  $pathParts = explode("/", $pathTokP);
81  $realPathParts = [];
82 
83  for ($i = 0, $realPathParts = []; $i < count($pathParts); $i++) {
84  if ($pathParts[$i] == '.') {
85  continue;
86  } elseif ($pathParts[$i] == '..') {
87  if (isset($realPathParts[0]) && $realPathParts[0] != '..' || $pathTokR != "") {
88  array_pop($realPathParts);
89  continue;
90  }
91  }
92 
93  $realPathParts[] = $pathParts[$i];
94  }
95 
96  return $pathTokR . implode('/', $realPathParts);
97  }
98 
104  public function allowedPath($haystackPath, $needlePath)
105  {
106  return strpos($this->getCleanPath($haystackPath), $this->getCleanPath($needlePath)) === 0;
107  }
108 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$pattern
Definition: website.php:22
allowedPath($haystackPath, $needlePath)
Definition: AbstractIo.php:104
$i
Definition: gallery.phtml:31