1: <?php
2:
3: namespace webfilesframework\io\request;
4:
5: /**
6: * description
7: *
8: * @author Sebastian Monzel < mail@sebastianmonzel.de >
9: * @since 0.1.7
10: */
11: class MUrl
12: {
13:
14: private $url;
15: //parsed url splitted in:
16: // PHP_URL_SCHEME,
17: // PHP_URL_HOST,
18: // PHP_URL_PORT,
19: // PHP_URL_USER,
20: // PHP_URL_PASS,
21: // PHP_URL_PATH,
22: // PHP_URL_QUERY and
23: // PHP_URL_FRAGMENT
24: //
25: //@see http://php.net/manual/de/function.parse-url.php
26:
27: private $parsedUrlArray;
28: private $params;
29:
30: private static $instance = null;
31:
32: public function __construct($url)
33: {
34: $this->url = $url;
35:
36: //split url
37: $this->parsedUrlArray = parse_url($url);
38:
39: //split params
40: if (isset($this->parsedUrlArray['query'])) {
41: $query = $this->parsedUrlArray['query'];
42: $queryParts = explode("&", $query);
43: foreach ($queryParts as $value) {
44: $paramParts = explode("=", $value);
45: if (count($paramParts) == 2) {
46: $key = $paramParts[0];
47: $value = $paramParts[1];
48: $this->params[$key] = $value;
49: }
50: }
51: }
52:
53: //@todo verhalten dazuimplementieren, wenn urlteil nicht vorhanden sind. zum beispiel: fallback zu aufrufurl-teile
54: }
55:
56: /**
57: *
58: * Enter description here ...
59: * @return MUrl
60: */
61: public static function getInstance()
62: {
63: if (MUrl::$instance == null) {
64: MUrl::$instance = new MUrl($_SERVER["HTTP_HOST"] . $_SERVER["SCRIPT_NAME"] . "?" . $_SERVER['QUERY_STRING']);
65: }
66: return MUrl::$instance;
67: }
68:
69: public function getReferer()
70: {
71: return $_SERVER['HTTP_REFERER'];
72: }
73:
74: public function getFullUrl()
75: {
76: return $this->url;
77: }
78:
79: public function getParam($paramName)
80: {
81: if ($this->paramExists($paramName)) {
82: return urldecode($this->params[$paramName]);
83: } else {
84: return NULL;
85: }
86:
87: }
88:
89: /**
90: * Checks if the param exists in the query part of the url.
91: * @param MBoolean : true if param exists, false if not.
92: * @return bool
93: */
94: public function paramExists($paramName)
95: {
96: return isset($this->params[$paramName]);
97: }
98:
99: public function getParams()
100: {
101: return $this->params;
102: }
103:
104: /**
105: *
106: * Enter description here ...
107: */
108: public function getPort()
109: {
110: return $this->parsedUrlArray['port'];
111: }
112:
113: /**
114: *
115: * Enter description here ...
116: */
117: public function getQueryString()
118: {
119: if (isset($this->parsedUrlArray['query'])) {
120: return $this->parsedUrlArray['query'];
121: } else {
122: return "";
123: }
124: }
125:
126:
127: }
128: