Url.php 745 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. class Url {
  3. private $path;
  4. private $arguments;
  5. public function __construct($path, $arguments) {
  6. $this->path = $path;
  7. $this->arguments = $arguments;
  8. }
  9. public function getPath() {
  10. return $this->path;
  11. }
  12. public function getPathElement($index) {
  13. return $this->path[$index];
  14. }
  15. public function getArgs() {
  16. return $this->arguments;
  17. }
  18. public function getArgumentElement($index) {
  19. return $this->arguments[$index];
  20. }
  21. public function toString() {
  22. $urlString = "/" . implode("/", $this->path);
  23. if(count($this->arguments) > 0) {
  24. $parts = array();
  25. foreach($this->arguments as $variable => $value) {
  26. $parts[] = $variable . "=" . $value;
  27. }
  28. $urlString .= "?" . implode("&", $parts);
  29. }
  30. return $urlString;
  31. }
  32. }