Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Uri.php
Go to the documentation of this file.
1 <?php
30 abstract class Zend_Uri
31 {
37  protected $_scheme = '';
38 
44  static protected $_config = array(
45  'allow_unwise' => false
46  );
47 
54  public function __toString()
55  {
56  try {
57  return $this->getUri();
58  } catch (Exception $e) {
59  trigger_error($e->getMessage(), E_USER_WARNING);
60  return '';
61  }
62  }
63 
72  public static function check($uri)
73  {
74  try {
75  $uri = self::factory($uri);
76  } catch (Exception $e) {
77  return false;
78  }
79 
80  return $uri->valid();
81  }
82 
96  public static function factory($uri = 'http', $className = null)
97  {
98  // Separate the scheme from the scheme-specific parts
99  $uri = explode(':', $uri, 2);
100  $scheme = strtolower($uri[0]);
101  $schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
102 
103  if (strlen($scheme) === 0) {
104  #require_once 'Zend/Uri/Exception.php';
105  throw new Zend_Uri_Exception('An empty string was supplied for the scheme');
106  }
107 
108  // Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
109  if (ctype_alnum($scheme) === false) {
110  #require_once 'Zend/Uri/Exception.php';
111  throw new Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
112  }
113 
114  if ($className === null) {
119  switch ($scheme) {
120  case 'http':
121  // Break intentionally omitted
122  case 'https':
123  $className = 'Zend_Uri_Http';
124  break;
125 
126  case 'mailto':
127  // TODO
128  default:
129  #require_once 'Zend/Uri/Exception.php';
130  throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported");
131  break;
132  }
133  }
134 
135  #require_once 'Zend/Loader.php';
136  try {
138  } catch (Exception $e) {
139  #require_once 'Zend/Uri/Exception.php';
140  throw new Zend_Uri_Exception("\"$className\" not found");
141  }
142 
143  $schemeHandler = new $className($scheme, $schemeSpecific);
144 
145  if (! $schemeHandler instanceof Zend_Uri) {
146  #require_once 'Zend/Uri/Exception.php';
147  throw new Zend_Uri_Exception("\"$className\" is not an instance of Zend_Uri");
148  }
149 
150  return $schemeHandler;
151  }
152 
158  public function getScheme()
159  {
160  if (empty($this->_scheme) === false) {
161  return $this->_scheme;
162  } else {
163  return false;
164  }
165  }
166 
172  static public function setConfig($config)
173  {
174  if ($config instanceof Zend_Config) {
175  $config = $config->toArray();
176  } elseif (!is_array($config)) {
177  throw new Zend_Uri_Exception("Config must be an array or an instance of Zend_Config.");
178  }
179 
180  foreach ($config as $k => $v) {
181  self::$_config[$k] = $v;
182  }
183  }
184 
192  abstract protected function __construct($scheme, $schemeSpecific = '');
193 
199  abstract public function getUri();
200 
206  abstract public function valid();
207 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static loadClass($class, $dirs=null)
Definition: Loader.php:52
$config
Definition: fraud_order.php:17
static setConfig($config)
Definition: Uri.php:172
static check($uri)
Definition: Uri.php:72
static factory($uri='http', $className=null)
Definition: Uri.php:96
__construct($scheme, $schemeSpecific='')
__toString()
Definition: Uri.php:54
getScheme()
Definition: Uri.php:158
$_scheme
Definition: Uri.php:37
static $_config
Definition: Uri.php:44
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31