composer package updates
[openemr.git] / vendor / zendframework / zend-uri / src / Http.php
blob56c0797ffb519d165983e76faccb05fd0809999b
1 <?php
2 /**
3 * @see https://github.com/zendframework/zend-uri for the canonical source repository
4 * @copyright Copyright (c) 2005-2018 Zend Technologies USA Inc. (https://www.zend.com)
5 * @license https://github.com/zendframework/zend-uri/blob/master/LICENSE.md New BSD License
6 */
8 namespace Zend\Uri;
10 /**
11 * HTTP URI handler
13 class Http extends Uri
15 /**
16 * @see Uri::$validSchemes
18 protected static $validSchemes = [
19 'http',
20 'https'
23 /**
24 * @see Uri::$defaultPorts
26 protected static $defaultPorts = [
27 'http' => 80,
28 'https' => 443,
31 /**
32 * @see Uri::$validHostTypes
34 protected $validHostTypes = self::HOST_DNS_OR_IPV4_OR_IPV6_OR_REGNAME;
36 /**
37 * User name as provided in authority of URI
38 * @var null|string
40 protected $user;
42 /**
43 * Password as provided in authority of URI
44 * @var null|string
46 protected $password;
48 /**
49 * Get the username part (before the ':') of the userInfo URI part
51 * @return string|null
53 public function getUser()
55 return $this->user;
58 /**
59 * Get the password part (after the ':') of the userInfo URI part
61 * @return string|null
63 public function getPassword()
65 return $this->password;
68 /**
69 * Get the User-info (usually user:password) part
71 * @return string|null
73 public function getUserInfo()
75 return $this->userInfo;
78 /**
79 * Set the username part (before the ':') of the userInfo URI part
81 * @param string|null $user
83 * @return self
85 public function setUser($user)
87 $this->user = null === $user ? null : (string) $user;
89 $this->buildUserInfo();
91 return $this;
94 /**
95 * Set the password part (after the ':') of the userInfo URI part
97 * @param string $password
99 * @return self
101 public function setPassword($password)
103 $this->password = null === $password ? null : (string) $password;
105 $this->buildUserInfo();
107 return $this;
111 * Set the URI User-info part (usually user:password)
113 * @param string|null $userInfo
115 * @return self
117 * @throws Exception\InvalidUriPartException If the schema definition does not have this part
119 public function setUserInfo($userInfo)
121 $this->userInfo = null === $userInfo ? null : (string) $userInfo;
123 $this->parseUserInfo();
125 return $this;
129 * Validate the host part of an HTTP URI
131 * This overrides the common URI validation method with a DNS or IP only
132 * default. Users may still enforce allowing other host types.
134 * @param string $host
135 * @param int $allowed
136 * @return bool
138 public static function validateHost($host, $allowed = self::HOST_DNS_OR_IPV4_OR_IPV6)
140 return parent::validateHost($host, $allowed);
144 * Parse the user info into username and password segments
146 * Parses the user information into username and password segments, and
147 * then sets the appropriate values.
149 * @return void
151 protected function parseUserInfo()
153 // No user information? we're done
154 if (null === $this->userInfo) {
155 $this->setUser(null);
156 $this->setPassword(null);
158 return;
161 // If no ':' separator, we only have a username
162 if (false === strpos($this->userInfo, ':')) {
163 $this->setUser($this->userInfo);
164 $this->setPassword(null);
165 return;
168 // Split on the ':', and set both user and password
169 list($this->user, $this->password) = explode(':', $this->userInfo, 2);
173 * Build the user info based on user and password
175 * Builds the user info based on the given user and password values
177 * @return void
179 protected function buildUserInfo()
181 if (null !== $this->password) {
182 $this->userInfo = $this->user . ':' . $this->password;
183 } else {
184 $this->userInfo = $this->user;
189 * Return the URI port
191 * If no port is set, will return the default port according to the scheme
193 * @return int
194 * @see Zend\Uri\Uri::getPort()
196 public function getPort()
198 if (empty($this->port)) {
199 if (array_key_exists($this->scheme, static::$defaultPorts)) {
200 return static::$defaultPorts[$this->scheme];
203 return $this->port;
207 * Parse a URI string
209 * @param string $uri
210 * @return Http
212 public function parse($uri)
214 parent::parse($uri);
216 if (empty($this->path)) {
217 $this->path = '/';
220 return $this;