1
|
|
|
<?php namespace Comodojo\Dispatcher\Request; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Dispatcher\Components\Parameters as ParametersTrait; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @package Comodojo Dispatcher |
7
|
|
|
* @author Marco Giovinazzi <[email protected]> |
8
|
|
|
* @author Marco Castiello <[email protected]> |
9
|
|
|
* @license GPL-3.0+ |
10
|
|
|
* |
11
|
|
|
* LICENSE: |
12
|
|
|
* |
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
16
|
|
|
* License, or (at your option) any later version. |
17
|
|
|
* |
18
|
|
|
* This program is distributed in the hope that it will be useful, |
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21
|
|
|
* GNU Affero General Public License for more details. |
22
|
|
|
* |
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
class Post { |
28
|
|
|
|
29
|
|
|
use ParametersTrait; |
30
|
|
|
|
31
|
|
|
protected $raw_parameters; |
32
|
|
|
|
33
|
|
|
public function __construct() { |
34
|
|
|
|
35
|
|
|
$this->parameters = self::getParameters(); |
36
|
|
|
|
37
|
|
|
$this->raw_parameters = self::getRawParameters(); |
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function raw() { |
42
|
|
|
|
43
|
|
|
return $this->raw_parameters; |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private static function getParameters() { |
|
|
|
|
48
|
|
|
|
49
|
|
|
switch( $_SERVER['REQUEST_METHOD'] ) { |
50
|
|
|
|
51
|
|
|
case 'POST': |
|
|
|
|
52
|
|
|
|
53
|
|
|
$parameters = $_POST; |
54
|
|
|
|
55
|
|
|
break; |
56
|
|
|
|
57
|
|
|
case 'PUT': |
58
|
|
|
case 'DELETE': |
|
|
|
|
59
|
|
|
|
60
|
|
|
parse_str(file_get_contents('php://input'), $parameters); |
61
|
|
|
|
62
|
|
|
break; |
63
|
|
|
|
64
|
|
|
default: |
|
|
|
|
65
|
|
|
|
66
|
|
|
$parameters = array(); |
67
|
|
|
|
68
|
|
|
break; |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $parameters; |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
private static function getRawParameters() { |
77
|
|
|
|
78
|
|
|
return file_get_contents('php://input'); |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
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: