3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
62 protected $validSchemes = array(
71 public function __construct($uri)
73 $parsed = parse_url($uri);
74 if (false === $parsed) {
79 $this->scheme
= isset($parsed['scheme']) ?
$parsed['scheme'] : null;
80 $this->host
= isset($parsed['host']) ?
$parsed['host'] : null;
81 $this->port
= isset($parsed['port']) ?
$parsed['port'] : null;
82 $this->user
= isset($parsed['user']) ?
$parsed['user'] : null;
83 $this->pass
= isset($parsed['pass']) ?
$parsed['pass'] : null;
84 $this->path
= isset($parsed['path']) ?
$parsed['path'] : null;
85 $this->query
= isset($parsed['query']) ?
$parsed['query'] : null;
86 $this->fragment
= isset($parsed['fragment']) ?
$parsed['fragment'] : null;
92 * Useful for chained validations
97 public static function factory($uri)
99 return new static($uri);
107 public function getHost()
113 * Retrieve the URI path
117 public function getPath()
123 * Retrieve the scheme
127 public function getScheme()
129 return $this->scheme
;
137 public function isValid()
139 if (false === $this->valid
) {
143 if ($this->scheme
&& !in_array($this->scheme
, $this->validSchemes
)) {
148 if ($this->path
&& substr($this->path
, 0, 1) != '/') {
154 // no host, but user and/or port... what?
155 if ($this->user ||
$this->port
) {
160 // Check path-only (no host) URI
161 if (substr($this->path
, 0, 2) == '//') {
167 if (! ($this->query ||
$this->fragment
)) {
168 // No host, path, query or fragment - this is not a valid URI
176 * Is the URI absolute?
180 public function isAbsolute()
182 return ($this->scheme
!== null);