Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Feed / Uri.php
blobc2403c5b75ac17446c0f11b412ca1586cad9048b
1 <?php
2 /**
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
8 */
10 namespace Zend\Feed;
12 class Uri
14 /**
15 * @var string
17 protected $fragment;
19 /**
20 * @var string
22 protected $host;
24 /**
25 * @var string
27 protected $pass;
29 /**
30 * @var string
32 protected $path;
34 /**
35 * @var int
37 protected $port;
39 /**
40 * @var string
42 protected $query;
44 /**
45 * @var string
47 protected $scheme;
49 /**
50 * @var string
52 protected $user;
54 /**
55 * @var bool
57 protected $valid;
59 /**
60 * Valid schemes
62 protected $validSchemes = array(
63 'http',
64 'https',
65 'file',
68 /**
69 * @param string $uri
71 public function __construct($uri)
73 $parsed = parse_url($uri);
74 if (false === $parsed) {
75 $this->valid = false;
76 return;
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;
89 /**
90 * Create an instance
92 * Useful for chained validations
94 * @param string $uri
95 * @return self
97 public static function factory($uri)
99 return new static($uri);
103 * Retrieve the host
105 * @return string
107 public function getHost()
109 return $this->host;
113 * Retrieve the URI path
115 * @return string
117 public function getPath()
119 return $this->path;
123 * Retrieve the scheme
125 * @return string
127 public function getScheme()
129 return $this->scheme;
133 * Is the URI valid?
135 * @return bool
137 public function isValid()
139 if (false === $this->valid) {
140 return false;
143 if ($this->scheme && !in_array($this->scheme, $this->validSchemes)) {
144 return false;
147 if ($this->host) {
148 if ($this->path && substr($this->path, 0, 1) != '/') {
149 return false;
151 return true;
154 // no host, but user and/or port... what?
155 if ($this->user || $this->port) {
156 return false;
159 if ($this->path) {
160 // Check path-only (no host) URI
161 if (substr($this->path, 0, 2) == '//') {
162 return false;
164 return true;
167 if (! ($this->query || $this->fragment)) {
168 // No host, path, query or fragment - this is not a valid URI
169 return false;
172 return true;
176 * Is the URI absolute?
178 * @return bool
180 public function isAbsolute()
182 return ($this->scheme !== null);