0
0

Uri.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures;
  11. use Psr\Http\Message\UriInterface;
  12. /**
  13. * @author Rougin Royce Gutib <rougingutib@gmail.com>
  14. */
  15. class Uri implements UriInterface
  16. {
  17. private $scheme = '';
  18. private $userInfo = '';
  19. private $host = '';
  20. private $port;
  21. private $path = '';
  22. private $query = '';
  23. private $fragment = '';
  24. private $uriString;
  25. public function __construct(string $uri = '')
  26. {
  27. $parts = parse_url($uri);
  28. $this->scheme = $parts['scheme'] ?? '';
  29. $this->userInfo = $parts['user'] ?? '';
  30. $this->host = $parts['host'] ?? '';
  31. $this->port = $parts['port'] ?? null;
  32. $this->path = $parts['path'] ?? '';
  33. $this->query = $parts['query'] ?? '';
  34. $this->fragment = $parts['fragment'] ?? '';
  35. $this->uriString = $uri;
  36. }
  37. public function getScheme(): string
  38. {
  39. return $this->scheme;
  40. }
  41. public function getAuthority(): string
  42. {
  43. if (empty($this->host)) {
  44. return '';
  45. }
  46. $authority = $this->host;
  47. if (!empty($this->userInfo)) {
  48. $authority = $this->userInfo.'@'.$authority;
  49. }
  50. $authority .= ':'.$this->port;
  51. return $authority;
  52. }
  53. public function getUserInfo(): string
  54. {
  55. return $this->userInfo;
  56. }
  57. public function getHost(): string
  58. {
  59. return $this->host;
  60. }
  61. public function getPort(): ?int
  62. {
  63. return $this->port;
  64. }
  65. public function getPath(): string
  66. {
  67. return $this->path;
  68. }
  69. public function getQuery(): string
  70. {
  71. return $this->query;
  72. }
  73. public function getFragment(): string
  74. {
  75. return $this->fragment;
  76. }
  77. /**
  78. * {@inheritdoc}
  79. *
  80. * @return static
  81. */
  82. public function withScheme($scheme)
  83. {
  84. throw new \BadMethodCallException('Not implemented.');
  85. }
  86. /**
  87. * {@inheritdoc}
  88. *
  89. * @return static
  90. */
  91. public function withUserInfo($user, $password = null)
  92. {
  93. throw new \BadMethodCallException('Not implemented.');
  94. }
  95. /**
  96. * {@inheritdoc}
  97. *
  98. * @return static
  99. */
  100. public function withHost($host)
  101. {
  102. throw new \BadMethodCallException('Not implemented.');
  103. }
  104. /**
  105. * {@inheritdoc}
  106. *
  107. * @return static
  108. */
  109. public function withPort($port)
  110. {
  111. throw new \BadMethodCallException('Not implemented.');
  112. }
  113. /**
  114. * {@inheritdoc}
  115. *
  116. * @return static
  117. */
  118. public function withPath($path)
  119. {
  120. throw new \BadMethodCallException('Not implemented.');
  121. }
  122. /**
  123. * {@inheritdoc}
  124. *
  125. * @return static
  126. */
  127. public function withQuery($query)
  128. {
  129. throw new \BadMethodCallException('Not implemented.');
  130. }
  131. /**
  132. * {@inheritdoc}
  133. *
  134. * @return static
  135. */
  136. public function withFragment($fragment)
  137. {
  138. throw new \BadMethodCallException('Not implemented.');
  139. }
  140. public function __toString(): string
  141. {
  142. return $this->uriString;
  143. }
  144. }