Completed
Push — 4.0 ( 2bab8b...b7ae43 )
by Marco
14:12
created

Model::uri()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Query;
8
use \Comodojo\Dispatcher\Request\UserAgent;
9
use \Comodojo\Dispatcher\Request\Method;
10
use \Comodojo\Dispatcher\Components\Timestamp as TimestampTrait;
11
12
/**
13
 *
14
 * @package     Comodojo dispatcher
15
 * @author      Marco Giovinazzi <[email protected]>
16
 * @license     GPL-3.0+
17
 *
18
 * LICENSE:
19
 *
20
 * This program is free software: you can redistribute it and/or modify
21
 * it under the terms of the GNU Affero General Public License as
22
 * published by the Free Software Foundation, either version 3 of the
23
 * License, or (at your option) any later version.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
 * GNU Affero General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU Affero General Public License
31
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
 */
33
34
class Model extends DispatcherClassModel {
35
36
    use TimestampTrait;
37
38
    private $headers = null;
39
40
    private $uri = null;
41
42
    private $useragent = null;
43
44
    private $post = null;
45
46
    private $query = null;
47
48
    private $method = null;
49
50
    public function __construct(Configuration $configuration, Logger $logger) {
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

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:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
51
52
        parent::__construct($configuration, $logger);
53
54
        $this->setTimestamp($_SERVER['REQUEST_TIME_FLOAT']);
55
56
        $this->headers = new Headers();
57
58
        $this->uri = HttpUri::createFromServer($_SERVER);
59
60
        $this->post = new Post();
61
62
        $this->query = new Query();
63
64
        $this->useragent = new UserAgent();
65
66
        $this->method = new Method();
67
68
    }
69
70
    public function headers() {
71
72
        return $this->headers;
73
74
    }
75
76
    public function uri() {
77
78
        return $this->uri;
79
80
    }
81
82
    public function post() {
83
84
        return $this->post;
85
86
    }
87
88
    public function query() {
89
90
        return $this->query;
91
92
    }
93
94
    public function useragent() {
95
96
        return $this->useragent;
97
98
    }
99
100
    public function method() {
101
102
        return $this->method;
103
    }
104
105
}
106