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
|
|
|
protected $mode = self::READONLY; |
36
|
|
|
|
37
|
5 |
|
public function __construct(Configuration $configuration, LoggerInterface $logger) { |
|
|
|
|
38
|
|
|
|
39
|
5 |
|
parent::__construct($configuration, $logger); |
40
|
|
|
|
41
|
5 |
|
$this->setTiming($_SERVER['REQUEST_TIME_FLOAT']); |
42
|
|
|
|
43
|
5 |
|
$this->setRaw('headers', new Headers()); |
44
|
5 |
|
$this->setRaw('uri', HttpUri::createFromServer($_SERVER)); |
45
|
5 |
|
$this->setRaw('post', new Post()); |
46
|
5 |
|
$this->setRaw('query', new Query()); |
47
|
5 |
|
$this->setRaw('useragent', new UserAgent()); |
48
|
5 |
|
$this->setRaw('method', new Method()); |
49
|
5 |
|
$this->setRaw('version', new Version()); |
50
|
5 |
|
$this->setRaw('files', Files::load()); |
51
|
|
|
|
52
|
5 |
|
} |
53
|
|
|
|
54
|
1 |
|
public function route() { |
55
|
|
|
|
56
|
1 |
|
return str_replace($this->configuration->get("base-uri"), "", $this->uri->getPath()); |
|
|
|
|
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
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: