1
|
|
|
<?php namespace Comodojo\Dispatcher\Request; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Dispatcher\Components\AbstractModel; |
4
|
|
|
use \Comodojo\Foundation\Timing\TimingTrait; |
5
|
|
|
use \Comodojo\Foundation\Base\Configuration; |
6
|
|
|
use \League\Uri\Schemes\Http as HttpUri; |
7
|
|
|
use \Psr\Log\LoggerInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @package Comodojo Dispatcher |
11
|
|
|
* @author Marco Giovinazzi <[email protected]> |
12
|
|
|
* @author Marco Castiello <[email protected]> |
13
|
|
|
* @license GPL-3.0+ |
14
|
|
|
* |
15
|
|
|
* LICENSE: |
16
|
|
|
* |
17
|
|
|
* This program is free software: you can redistribute it and/or modify |
18
|
|
|
* it under the terms of the GNU Affero General Public License as |
19
|
|
|
* published by the Free Software Foundation, either version 3 of the |
20
|
|
|
* License, or (at your option) any later version. |
21
|
|
|
* |
22
|
|
|
* This program is distributed in the hope that it will be useful, |
23
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
24
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25
|
|
|
* GNU Affero General Public License for more details. |
26
|
|
|
* |
27
|
|
|
* You should have received a copy of the GNU Affero General Public License |
28
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
class Model extends AbstractModel { |
32
|
|
|
|
33
|
|
|
use TimingTrait; |
34
|
|
|
|
35
|
5 |
|
public function __construct(Configuration $configuration, LoggerInterface $logger) { |
|
|
|
|
36
|
|
|
|
37
|
5 |
|
parent::__construct($configuration, $logger); |
38
|
|
|
|
39
|
5 |
|
$this->setTiming($_SERVER['REQUEST_TIME_FLOAT']); |
40
|
|
|
|
41
|
5 |
|
$this->setHeaders(new Headers()); |
42
|
5 |
|
$this->setUri(HttpUri::createFromServer($_SERVER)); |
43
|
5 |
|
$this->setPost(new Post()); |
44
|
5 |
|
$this->setQuery(new Query()); |
45
|
5 |
|
$this->setUserAgent(new UserAgent()); |
46
|
5 |
|
$this->setMethod(new Method()); |
47
|
5 |
|
$this->setVersion(new Version()); |
48
|
5 |
|
$this->setFiles(Files::load()); |
49
|
|
|
|
50
|
5 |
|
} |
51
|
|
|
|
52
|
|
|
public function getHeaders() { |
53
|
|
|
|
54
|
|
|
return $this->headers; |
|
|
|
|
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
5 |
|
public function setHeaders(Headers $headers) { |
59
|
|
|
|
60
|
5 |
|
$this->headers = $headers; |
61
|
|
|
|
62
|
5 |
|
return $this; |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function getUri() { |
67
|
|
|
|
68
|
1 |
|
return $this->uri; |
|
|
|
|
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
5 |
|
public function setUri(HttpUri $uri) { |
73
|
|
|
|
74
|
5 |
|
$this->uri = $uri; |
75
|
|
|
|
76
|
5 |
|
return $this; |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getPost() { |
81
|
|
|
|
82
|
|
|
return $this->post; |
|
|
|
|
83
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
5 |
|
public function setPost(Post $post) { |
87
|
|
|
|
88
|
5 |
|
$this->post = $post; |
89
|
|
|
|
90
|
5 |
|
return $this; |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getQuery() { |
95
|
|
|
|
96
|
|
|
return $this->query; |
|
|
|
|
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
5 |
|
public function setQuery(Query $query) { |
101
|
|
|
|
102
|
5 |
|
$this->query = $query; |
103
|
|
|
|
104
|
5 |
|
return $this; |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function getUserAgent() { |
109
|
|
|
|
110
|
|
|
return $this->useragent; |
|
|
|
|
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
5 |
|
public function setUserAgent(UserAgent $useragent) { |
115
|
|
|
|
116
|
5 |
|
$this->useragent = $useragent; |
117
|
|
|
|
118
|
5 |
|
return $this; |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
3 |
|
public function getMethod() { |
123
|
|
|
|
124
|
3 |
|
return $this->method; |
|
|
|
|
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
128
|
5 |
|
public function setMethod(Method $method) { |
129
|
|
|
|
130
|
5 |
|
$this->method = $method; |
131
|
|
|
|
132
|
5 |
|
return $this; |
133
|
|
|
|
134
|
|
|
} |
135
|
|
|
|
136
|
4 |
|
public function getVersion() { |
137
|
|
|
|
138
|
4 |
|
return $this->version; |
|
|
|
|
139
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
5 |
|
public function setVersion(Version $version) { |
143
|
|
|
|
144
|
5 |
|
$this->version = $version; |
145
|
|
|
|
146
|
5 |
|
return $this; |
147
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function getFiles() { |
151
|
|
|
|
152
|
|
|
return $this->files; |
|
|
|
|
153
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
5 |
|
public function setFiles(array $files) { |
157
|
|
|
|
158
|
5 |
|
$this->files = $files; |
159
|
|
|
|
160
|
5 |
|
return $this; |
161
|
|
|
|
162
|
|
|
} |
163
|
|
|
|
164
|
1 |
|
public function route() { |
165
|
|
|
|
166
|
1 |
|
return str_replace($this->getConfiguration()->get("base-uri"), "", $this->getUri()->getPath()); |
167
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
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: