Uri.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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($uri = '')
  26. {
  27. $parts = parse_url($uri);
  28. $this->scheme = isset($parts['scheme']) ? $parts['scheme'] : '';
  29. $this->userInfo = isset($parts['user']) ? $parts['user'] : '';
  30. $this->host = isset($parts['host']) ? $parts['host'] : '';
  31. $this->port = isset($parts['port']) ? $parts['port'] : null;
  32. $this->path = isset($parts['path']) ? $parts['path'] : '';
  33. $this->query = isset($parts['query']) ? $parts['query'] : '';
  34. $this->fragment = isset($parts['fragment']) ? $parts['fragment'] : '';
  35. $this->uriString = $uri;
  36. }
  37. public function getScheme()
  38. {
  39. return $this->scheme;
  40. }
  41. public function getAuthority()
  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()
  54. {
  55. return $this->userInfo;
  56. }
  57. public function getHost()
  58. {
  59. return $this->host;
  60. }
  61. public function getPort()
  62. {
  63. return $this->port;
  64. }
  65. public function getPath()
  66. {
  67. return $this->path;
  68. }
  69. public function getQuery()
  70. {
  71. return $this->query;
  72. }
  73. public function getFragment()
  74. {
  75. return $this->fragment;
  76. }
  77. public function withScheme($scheme)
  78. {
  79. throw new \BadMethodCallException('Not implemented.');
  80. }
  81. public function withUserInfo($user, $password = null)
  82. {
  83. throw new \BadMethodCallException('Not implemented.');
  84. }
  85. public function withHost($host)
  86. {
  87. throw new \BadMethodCallException('Not implemented.');
  88. }
  89. public function withPort($port)
  90. {
  91. throw new \BadMethodCallException('Not implemented.');
  92. }
  93. public function withPath($path)
  94. {
  95. throw new \BadMethodCallException('Not implemented.');
  96. }
  97. public function withQuery($query)
  98. {
  99. throw new \BadMethodCallException('Not implemented.');
  100. }
  101. public function withFragment($fragment)
  102. {
  103. throw new \BadMethodCallException('Not implemented.');
  104. }
  105. public function __toString()
  106. {
  107. return $this->uriString;
  108. }
  109. }