comparison vendor/zendframework/zend-diactoros/src/Uri.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
109 * @param string $uri 109 * @param string $uri
110 * @throws InvalidArgumentException on non-string $uri argument 110 * @throws InvalidArgumentException on non-string $uri argument
111 */ 111 */
112 public function __construct($uri = '') 112 public function __construct($uri = '')
113 { 113 {
114 if ('' === $uri) {
115 return;
116 }
117
114 if (! is_string($uri)) { 118 if (! is_string($uri)) {
115 throw new InvalidArgumentException(sprintf( 119 throw new InvalidArgumentException(sprintf(
116 'URI passed to constructor must be a string; received "%s"', 120 'URI passed to constructor must be a string; received "%s"',
117 (is_object($uri) ? get_class($uri) : gettype($uri)) 121 is_object($uri) ? get_class($uri) : gettype($uri)
118 )); 122 ));
119 } 123 }
120 124
121 if ('' !== $uri) { 125 $this->parseUri($uri);
122 $this->parseUri($uri);
123 }
124 } 126 }
125 127
126 /** 128 /**
127 * Operations to perform on clone. 129 * Operations to perform on clone.
128 * 130 *
244 { 246 {
245 if (! is_string($scheme)) { 247 if (! is_string($scheme)) {
246 throw new InvalidArgumentException(sprintf( 248 throw new InvalidArgumentException(sprintf(
247 '%s expects a string argument; received %s', 249 '%s expects a string argument; received %s',
248 __METHOD__, 250 __METHOD__,
249 (is_object($scheme) ? get_class($scheme) : gettype($scheme)) 251 is_object($scheme) ? get_class($scheme) : gettype($scheme)
250 )); 252 ));
251 } 253 }
252 254
253 $scheme = $this->filterScheme($scheme); 255 $scheme = $this->filterScheme($scheme);
254 256
275 { 277 {
276 if (! is_string($user)) { 278 if (! is_string($user)) {
277 throw new InvalidArgumentException(sprintf( 279 throw new InvalidArgumentException(sprintf(
278 '%s expects a string user argument; received %s', 280 '%s expects a string user argument; received %s',
279 __METHOD__, 281 __METHOD__,
280 (is_object($user) ? get_class($user) : gettype($user)) 282 is_object($user) ? get_class($user) : gettype($user)
281 )); 283 ));
282 } 284 }
283 if (null !== $password && ! is_string($password)) { 285 if (null !== $password && ! is_string($password)) {
284 throw new InvalidArgumentException(sprintf( 286 throw new InvalidArgumentException(sprintf(
285 '%s expects a string password argument; received %s', 287 '%s expects a string or null password argument; received %s',
286 __METHOD__, 288 __METHOD__,
287 (is_object($password) ? get_class($password) : gettype($password)) 289 is_object($password) ? get_class($password) : gettype($password)
288 )); 290 ));
289 } 291 }
290 292
291 $info = $this->filterUserInfoPart($user); 293 $info = $this->filterUserInfoPart($user);
292 if ($password) { 294 if (null !== $password) {
293 $info .= ':' . $this->filterUserInfoPart($password); 295 $info .= ':' . $this->filterUserInfoPart($password);
294 } 296 }
295 297
296 if ($info === $this->userInfo) { 298 if ($info === $this->userInfo) {
297 // Do nothing if no change was made. 299 // Do nothing if no change was made.
311 { 313 {
312 if (! is_string($host)) { 314 if (! is_string($host)) {
313 throw new InvalidArgumentException(sprintf( 315 throw new InvalidArgumentException(sprintf(
314 '%s expects a string argument; received %s', 316 '%s expects a string argument; received %s',
315 __METHOD__, 317 __METHOD__,
316 (is_object($host) ? get_class($host) : gettype($host)) 318 is_object($host) ? get_class($host) : gettype($host)
317 )); 319 ));
318 } 320 }
319 321
320 if ($host === $this->host) { 322 if ($host === $this->host) {
321 // Do nothing if no change was made. 323 // Do nothing if no change was made.
331 /** 333 /**
332 * {@inheritdoc} 334 * {@inheritdoc}
333 */ 335 */
334 public function withPort($port) 336 public function withPort($port)
335 { 337 {
336 if (! is_numeric($port) && $port !== null) {
337 throw new InvalidArgumentException(sprintf(
338 'Invalid port "%s" specified; must be an integer, an integer string, or null',
339 (is_object($port) ? get_class($port) : gettype($port))
340 ));
341 }
342
343 if ($port !== null) { 338 if ($port !== null) {
339 if (! is_numeric($port) || is_float($port)) {
340 throw new InvalidArgumentException(sprintf(
341 'Invalid port "%s" specified; must be an integer, an integer string, or null',
342 is_object($port) ? get_class($port) : gettype($port)
343 ));
344 }
345
344 $port = (int) $port; 346 $port = (int) $port;
345 } 347 }
346 348
347 if ($port === $this->port) { 349 if ($port === $this->port) {
348 // Do nothing if no change was made. 350 // Do nothing if no change was made.
435 { 437 {
436 if (! is_string($fragment)) { 438 if (! is_string($fragment)) {
437 throw new InvalidArgumentException(sprintf( 439 throw new InvalidArgumentException(sprintf(
438 '%s expects a string argument; received %s', 440 '%s expects a string argument; received %s',
439 __METHOD__, 441 __METHOD__,
440 (is_object($fragment) ? get_class($fragment) : gettype($fragment)) 442 is_object($fragment) ? get_class($fragment) : gettype($fragment)
441 )); 443 ));
442 } 444 }
443 445
444 $fragment = $this->filterFragment($fragment); 446 $fragment = $this->filterFragment($fragment);
445 447
557 559
558 if ('' === $scheme) { 560 if ('' === $scheme) {
559 return ''; 561 return '';
560 } 562 }
561 563
562 if (! array_key_exists($scheme, $this->allowedSchemes)) { 564 if (! isset($this->allowedSchemes[$scheme])) {
563 throw new InvalidArgumentException(sprintf( 565 throw new InvalidArgumentException(sprintf(
564 'Unsupported scheme "%s"; must be any empty string or in the set (%s)', 566 'Unsupported scheme "%s"; must be any empty string or in the set (%s)',
565 $scheme, 567 $scheme,
566 implode(', ', array_keys($this->allowedSchemes)) 568 implode(', ', array_keys($this->allowedSchemes))
567 )); 569 ));
653 * @return array A value with exactly two elements, key and value 655 * @return array A value with exactly two elements, key and value
654 */ 656 */
655 private function splitQueryValue($value) 657 private function splitQueryValue($value)
656 { 658 {
657 $data = explode('=', $value, 2); 659 $data = explode('=', $value, 2);
658 if (1 === count($data)) { 660 if (! isset($data[1])) {
659 $data[] = null; 661 $data[] = null;
660 } 662 }
661 return $data; 663 return $data;
662 } 664 }
663 665