1
|
|
|
<?php namespace Comodojo\Dispatcher\Request; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Components\Model as DispatcherClassModel; |
4
|
|
|
use \League\Uri\Schemes\Http as HttpUri; |
5
|
|
|
use \Comodojo\Dispatcher\Request\Headers; |
6
|
|
|
use \Comodojo\Dispatcher\Request\Post; |
7
|
|
|
use \Comodojo\Dispatcher\Request\UserAgent; |
8
|
|
|
use \Comodojo\Dispatcher\Request\Method; |
9
|
|
|
use \Comodojo\Dispatcher\Components\Timestamp as TimestampTrait; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* |
13
|
|
|
* @package Comodojo dispatcher |
14
|
|
|
* @author Marco Giovinazzi <[email protected]> |
15
|
|
|
* @license GPL-3.0+ |
16
|
|
|
* |
17
|
|
|
* LICENSE: |
18
|
|
|
* |
19
|
|
|
* This program is free software: you can redistribute it and/or modify |
20
|
|
|
* it under the terms of the GNU Affero General Public License as |
21
|
|
|
* published by the Free Software Foundation, either version 3 of the |
22
|
|
|
* License, or (at your option) any later version. |
23
|
|
|
* |
24
|
|
|
* This program is distributed in the hope that it will be useful, |
25
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
26
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
27
|
|
|
* GNU Affero General Public License for more details. |
28
|
|
|
* |
29
|
|
|
* You should have received a copy of the GNU Affero General Public License |
30
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
class Model extends DispatcherClassModel { |
34
|
|
|
|
35
|
|
|
use TimestampTrait; |
36
|
|
|
|
37
|
|
|
private $headers = null; |
38
|
|
|
|
39
|
|
|
private $uri = null; |
40
|
|
|
|
41
|
|
|
private $useragent = null; |
42
|
|
|
|
43
|
|
|
private $post = null; |
44
|
|
|
|
45
|
|
|
private $method = null; |
46
|
|
|
|
47
|
|
|
public function __construct(Configuration $configuration, Logger $logger) { |
|
|
|
|
48
|
|
|
|
49
|
|
|
parent::__construct($configuration, $logger); |
50
|
|
|
|
51
|
|
|
$this->setTimestamp($_SERVER['REQUEST_TIME_FLOAT']); |
52
|
|
|
|
53
|
|
|
$this->headers = new Headers(); |
54
|
|
|
|
55
|
|
|
$this->uri = HttpUri::createFromServer($_SERVER); |
56
|
|
|
|
57
|
|
|
$this->post = new Post(); |
58
|
|
|
|
59
|
|
|
$this->useragent = new UserAgent(); |
60
|
|
|
|
61
|
|
|
$this->method = new Method(); |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function headers() { |
66
|
|
|
|
67
|
|
|
return $this->headers; |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function uri() { |
72
|
|
|
|
73
|
|
|
return $this->uri; |
74
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function post() { |
78
|
|
|
|
79
|
|
|
return $this->post; |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function useragent() { |
84
|
|
|
|
85
|
|
|
return $this->useragent; |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function method() { |
90
|
|
|
|
91
|
|
|
return $this->method; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
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: