1 | <?php |
||
5 | class Resource |
||
6 | { |
||
7 | /** |
||
8 | * Curernt URI location |
||
9 | * @var string |
||
10 | */ |
||
11 | protected $uri; |
||
12 | |||
13 | /** |
||
14 | * Current HTTP method/verb |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $method; |
||
18 | |||
19 | /** |
||
20 | * Create the resource, set the URL and HTTP method manually if desired |
||
21 | * URI will default to REQUEST_URI |
||
22 | * HTTP method will default to REQUEST_METHOD |
||
23 | * |
||
24 | * @param string $uri URI for the resource |
||
25 | * @param string $httpMethod HTTP method for the resource |
||
26 | */ |
||
27 | public function __construct($uri = null, $httpMethod = null) |
||
36 | |||
37 | /** |
||
38 | * Set the curren tHTTP method |
||
39 | * |
||
40 | * @param string $method HTTP method (ex: GET, POST) |
||
41 | */ |
||
42 | public function setHttpMethod($method) |
||
46 | |||
47 | /** |
||
48 | * Get the current HTTP method |
||
49 | * |
||
50 | * @return string HTTP method currently set |
||
51 | */ |
||
52 | public function getHttpMethod() |
||
56 | |||
57 | /** |
||
58 | * Set the current URI for the resource |
||
59 | * |
||
60 | * @param string $uri URI path |
||
61 | */ |
||
62 | public function setUri($uri) |
||
66 | |||
67 | /** |
||
68 | * Get the curent URI setting |
||
69 | * |
||
70 | * @return string Current URI setting |
||
71 | */ |
||
72 | public function getUri($parsed = false) |
||
76 | |||
77 | public function getParams() |
||
92 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: