UrlParser.php 600 B

12345678910111213141516171819202122
  1. <?php
  2. require_once "../libs/Url.php";
  3. class UrlParser {
  4. public static function getInstance() {
  5. return new UrlParser();
  6. }
  7. public function getUrlData() {
  8. $data = array();
  9. $urlData = explode("?", $_SERVER['REQUEST_URI']);
  10. $path = explode("/", trim($urlData[0], "/"));
  11. $queryParams = array();
  12. if(isset($urlData[1])) {
  13. $queryParamData = explode("&", $urlData[1]);
  14. foreach($queryParamData as $string) {
  15. $singleParam = explode("=", $string);
  16. $queryParams[$singleParam[0]] = isset($singleParam[1]) ? $singleParam[1] : true;
  17. }
  18. }
  19. return new Url($path, $queryParams);
  20. }
  21. }