ServletRequestWrapper   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 21.88%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 164
c 0
b 0
f 0
ccs 7
cts 32
cp 0.2188
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A injectRequest() 0 4 1
A setRequest() 0 4 1
A getRequest() 0 4 1
A getParameterMap() 0 4 1
A getBodyStream() 0 4 1
A setBodyStream() 0 4 1
A getVersion() 0 4 1
A getParameter() 0 4 1
A getPart() 0 4 1
A getParts() 0 4 1
A setDispatched() 0 4 1
A isDispatched() 0 4 1
A getPathInfo() 0 4 1
A getServletPath() 0 4 1
1
<?php
2
3
/**
4
 * \AppserverIo\Psr\Servlet\ServletRequestWrapper
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io-psr/servlet
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Psr\Servlet;
22
23
/**
24
 * A servlet request implementation.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2015 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/appserver-io-psr/servlet
30
 * @link      http://www.appserver.io
31
 */
32
class ServletRequestWrapper implements ServletRequestInterface
33
{
34
35
    /**
36
     * The servlet request instance.
37
     *
38
     * @var \AppserverIo\Psr\Servlet\ServletRequestInterface
39
     */
40
    protected $request;
41
42
    /**
43
     * Injects the passed request instance into this servlet request.
44
     *
45
     * @param \AppserverIo\Psr\Servlet\ServletRequestInterface $request The request instance used for initialization
46
     *
47
     * @return void
48
     */
49 2
    public function injectRequest(ServletRequestInterface $request)
50
    {
51 2
        $this->request = $request;
52 2
    }
53
54
    /**
55
     * Sets the passed request instance into this servlet request.
56
     *
57
     * @param \AppserverIo\Psr\Servlet\ServletRequestInterface $request The request instance used for initialization
58
     *
59
     * @return void
60
     */
61
    public function setRequest(ServletRequestInterface $request)
62
    {
63
        $this->request = $request;
64
    }
65
66
    /**
67
     * Returns the wrapped request object.
68
     *
69
     * @return \AppserverIo\Psr\Servlet\ServletRequestInterface The wrapped request object
70
     */
71 1
    public function getRequest()
72
    {
73 1
        return $this->request;
74
    }
75
76
    /**
77
     * Returns an array with all request parameters.
78
     *
79
     * @return array The array with the request parameters
80
     */
81
    public function getParameterMap()
82
    {
83
        return $this->getRequest()->getParameterMap();
84
    }
85
86
    /**
87
     * Return request content.
88
     *
89
     * @return resource The request content
90
     */
91
    public function getBodyStream()
92
    {
93
        return $this->getRequest()->getBodyStream();
94
    }
95
96
    /**
97
     * Resets the stream resource pointing to body content.
98
     *
99
     * @param resource $bodyStream The body content stream resource
100
     *
101
     * @return void
102
     */
103
    public function setBodyStream($bodyStream)
104
    {
105
        $this->getRequest()->setBodyStream($bodyStream);
106
    }
107
108
    /**
109
     * Returns protocol version
110
     *
111
     * @return string
112
     */
113 1
    public function getVersion()
114
    {
115 1
        return $this->getRequest()->getVersion();
116
    }
117
118
    /**
119
     * Returns the parameter with the passed name if available or null
120
     * if the parameter not exists.
121
     *
122
     * @param string  $name   The name of the parameter to return
123
     * @param integer $filter The filter to use
124
     *
125
     * @return string|null
126
     */
127
    public function getParameter($name, $filter = FILTER_SANITIZE_STRING)
128
    {
129
        return filter_var($this->getRequest()->getParameter($name), $filter);
130
    }
131
132
    /**
133
     * Returns a part object by given name
134
     *
135
     * @param string $name The name of the form part
136
     *
137
     * @return \AppserverIo\Psr\HttpMessage\PartInterface
138
     */
139
    public function getPart($name)
140
    {
141
        return $this->getRequest()->getPart($name);
142
    }
143
144
    /**
145
     * Returns the parts collection as array
146
     *
147
     * @return array A collection of HttpPart objects
148
     */
149
    public function getParts()
150
    {
151
        return $this->getRequest()->getParts();
152
    }
153
154
    /**
155
     * Sets the flag to mark the request dispatched.
156
     *
157
     * @param boolean $dispatched TRUE if the request has already been dispatched, else FALSE
158
     *
159
     * @return void
160
     */
161
    public function setDispatched($dispatched = true)
162
    {
163
        $this->getRequest()->setDispatched($dispatched);
164
    }
165
166
    /**
167
     * Sets the flag that shows if the request has already been dispatched.
168
     *
169
     * @return boolean TRUE if the request has already been dispatched, else FALSE
170
     */
171
    public function isDispatched()
172
    {
173
        return $this->getRequest()->isDispatched();
174
    }
175
176
    /**
177
     * Returns the absolute path info started from the context path.
178
     *
179
     * @return string The absolute path
180
     */
181
    public function getPathInfo()
182
    {
183
        return $this->getRequest()->getPathInfo();
184
    }
185
186
    /**
187
     * Returns the path to the servlet used to handle this request.
188
     *
189
     * @return string The path to the servlet
190
     */
191
    public function getServletPath()
192
    {
193
        return $this->getRequest()->getServletPath();
194
    }
195
}
196