1
|
|
|
<?php namespace Comodojo\Dispatcher\Request; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Dispatcher\Components\Model as DispatcherClassModel; |
4
|
|
|
use \Comodojo\Dispatcher\Components\Timestamp as TimestampTrait; |
5
|
|
|
use \Comodojo\Dispatcher\Components\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 DispatcherClassModel { |
32
|
|
|
|
33
|
|
|
use TimestampTrait; |
34
|
|
|
|
35
|
5 |
|
public function __construct(Configuration $configuration, LoggerInterface $logger) { |
|
|
|
|
36
|
|
|
|
37
|
5 |
|
parent::__construct($configuration, $logger); |
38
|
|
|
|
39
|
5 |
|
$this->setTimestamp($_SERVER['REQUEST_TIME_FLOAT']); |
40
|
|
|
|
41
|
5 |
|
$this->headers = new Headers(); |
|
|
|
|
42
|
|
|
|
43
|
5 |
|
$this->uri = HttpUri::createFromServer($_SERVER); |
|
|
|
|
44
|
|
|
|
45
|
5 |
|
$this->post = new Post(); |
|
|
|
|
46
|
|
|
|
47
|
5 |
|
$this->query = new Query(); |
|
|
|
|
48
|
|
|
|
49
|
5 |
|
$this->useragent = new UserAgent(); |
|
|
|
|
50
|
|
|
|
51
|
5 |
|
$this->method = new Method(); |
|
|
|
|
52
|
|
|
|
53
|
5 |
|
$this->version = new Version(); |
|
|
|
|
54
|
|
|
|
55
|
5 |
|
$repo = (!empty($configuration->get('repository')))?$configuration->get('base-path') . "/" . $configuration->get('repository'):''; |
56
|
|
|
|
57
|
5 |
|
$this->file = File::fromUploadedFiles($repo); |
|
|
|
|
58
|
|
|
|
59
|
5 |
|
} |
60
|
|
|
|
61
|
1 |
|
public function route() { |
62
|
|
|
|
63
|
1 |
|
return str_replace($this->configuration->get("base-uri"), "", $this->uri->getPath()); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
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: