url-rewrite-zonder-modrewrite-class
Gesponsorde koppelingen
PHP script bestanden
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
final class Request {
// object instance
private static $instance;
/**
* In this var are the parameters stored
*
* @var array
*/
static private $params = array();
/**
* prevent direct access and cloning
*
*/
private function __construct(){}
private function __clone(){}
/**
* create an instance of self
*
* @return Request
*/
public function getRequest() {
if (!self::$instance instanceof self) {
self::$instance = new self();
self::parseUrl();
}
return self::$instance;
}
/**
* This method will parse the url and put it as an array
* in self::$params.
*
*/
private function parseUrl(){
$pathInfo = explode('/', trim($_SERVER['PATH_INFO'], '/'));
$myPath = array();
for($i=0, $count=count($pathInfo); $i+1<$count && $count>1; $i+=2) {
$myPath[(string) $pathInfo[$i]] = (string) $pathInfo[$i+1];
}
self::$params = $myPath;
}
/**
* This function will return one of the items
*
* @param string $key
* @param mixed $default
* @return string/mixed.
*/
public function getParam($key, $default = null){
$key = (string) $key;
if(isset(self::$params[$key])){
return self::$params[$key];
}
return $default;
}
/**
* A magic method wich does the same as self::getParam()
*
* @param string $key
* @return string
*/
public function __get($key){
return self::getParam($key);
}
/**
* This method will return all the values of self::$params
*
* @return unknown
*/
public function getParams(){
return self::$params;
}
}
var_dump(Request::getRequest()->index);
var_dump(Request::getRequest()->getParams());
?>
final class Request {
// object instance
private static $instance;
/**
* In this var are the parameters stored
*
* @var array
*/
static private $params = array();
/**
* prevent direct access and cloning
*
*/
private function __construct(){}
private function __clone(){}
/**
* create an instance of self
*
* @return Request
*/
public function getRequest() {
if (!self::$instance instanceof self) {
self::$instance = new self();
self::parseUrl();
}
return self::$instance;
}
/**
* This method will parse the url and put it as an array
* in self::$params.
*
*/
private function parseUrl(){
$pathInfo = explode('/', trim($_SERVER['PATH_INFO'], '/'));
$myPath = array();
for($i=0, $count=count($pathInfo); $i+1<$count && $count>1; $i+=2) {
$myPath[(string) $pathInfo[$i]] = (string) $pathInfo[$i+1];
}
self::$params = $myPath;
}
/**
* This function will return one of the items
*
* @param string $key
* @param mixed $default
* @return string/mixed.
*/
public function getParam($key, $default = null){
$key = (string) $key;
if(isset(self::$params[$key])){
return self::$params[$key];
}
return $default;
}
/**
* A magic method wich does the same as self::getParam()
*
* @param string $key
* @return string
*/
public function __get($key){
return self::getParam($key);
}
/**
* This method will return all the values of self::$params
*
* @return unknown
*/
public function getParams(){
return self::$params;
}
}
var_dump(Request::getRequest()->index);
var_dump(Request::getRequest()->getParams());
?>