Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RealPath.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Filter/Interface.php';
26 
34 {
38  protected $_exists = true;
39 
45  public function __construct($options = true)
46  {
47  $this->setExists($options);
48  }
49 
55  public function getExists()
56  {
57  return $this->_exists;
58  }
59 
68  public function setExists($exists)
69  {
70  if ($exists instanceof Zend_Config) {
71  $exists = $exists->toArray();
72  }
73 
74  if (is_array($exists)) {
75  if (isset($exists['exists'])) {
76  $exists = (boolean) $exists['exists'];
77  }
78  }
79 
80  $this->_exists = (boolean) $exists;
81  return $this;
82  }
83 
92  public function filter($value)
93  {
94  $path = (string) $value;
95  if ($this->_exists) {
96  return realpath($path);
97  }
98 
99  $realpath = @realpath($path);
100  if ($realpath) {
101  return $realpath;
102  }
103 
104  $drive = '';
105  if (substr(PHP_OS, 0, 3) == 'WIN') {
106  $path = preg_replace('/[\\\\\/]/', DIRECTORY_SEPARATOR, $path);
107  if (preg_match('/([a-zA-Z]\:)(.*)/', $path, $matches)) {
108  list($fullMatch, $drive, $path) = $matches;
109  } else {
110  $cwd = getcwd();
111  $drive = substr($cwd, 0, 2);
112  if (substr($path, 0, 1) != DIRECTORY_SEPARATOR) {
113  $path = substr($cwd, 3) . DIRECTORY_SEPARATOR . $path;
114  }
115  }
116  } elseif (substr($path, 0, 1) != DIRECTORY_SEPARATOR) {
117  $path = getcwd() . DIRECTORY_SEPARATOR . $path;
118  }
119 
120  $stack = array();
121  $parts = explode(DIRECTORY_SEPARATOR, $path);
122  foreach ($parts as $dir) {
123  if (strlen($dir) && $dir !== '.') {
124  if ($dir == '..') {
125  array_pop($stack);
126  } else {
127  array_push($stack, $dir);
128  }
129  }
130  }
131 
132  return $drive . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $stack);
133  }
134 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct($options=true)
Definition: RealPath.php:45
$value
Definition: gender.phtml:16
setExists($exists)
Definition: RealPath.php:68