HttpServletRequestWrapper::addPart()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * \AppserverIo\Psr\Servlet\Http\HttpServletRequestWrapper
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\Http;
22
23
use AppserverIo\Psr\HttpMessage\PartInterface;
24
use AppserverIo\Psr\HttpMessage\CookieInterface;
25
use AppserverIo\Psr\Servlet\ServletRequestWrapper;
26
27
/**
28
 * A servlet request implementation.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2015 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io-psr/servlet
34
 * @link      http://www.appserver.io
35
 */
36
class HttpServletRequestWrapper extends ServletRequestWrapper implements HttpServletRequestInterface
37
{
38
39
    /**
40
     * Injects the passed request instance into this servlet request.
41
     *
42
     * @param \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface $request The request instance used for initialization
43
     *
44
     * @return void
45
     */
46 1
    public function injectHttpRequest(HttpServletRequestInterface $request)
47
    {
48 1
        $this->injectRequest($request);
49 1
    }
50
51
    /**
52
     * Returns the base modifier which allows for base path generation within rewritten URL environments
53
     *
54
     * @return string
55
     */
56
    public function getBaseModifier()
57
    {
58
        return $this->getRequest()->getBaseModifier();
59
    }
60
61
    /**
62
     * Returns the application context name (application name prefixed with a slash) for the actual request.
63
     *
64
     * @return string The application context name
65
     */
66
    public function getContextPath()
67
    {
68
        return $this->getRequest()->getContextPath();
69
    }
70
71
    /**
72
     * @return \AppserverIo\Psr\Servlet\Http\HttpServletRequestInterface
73
     */
74 1
    public function getRequest()
75
    {
76 1
        return $this->request;
77
    }
78
79
    /**
80
     * Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
81
     *
82
     * @return string
83
     */
84
    public function getRequestUri()
85
    {
86
        return $this->getRequest()->getRequestUri();
87
    }
88
89
    /**
90
     * Returns an part instance
91
     *
92
     * @return \AppserverIo\Psr\HttpMessage\PartInterface
93
     */
94
    public function getHttpPartInstance()
95
    {
96
        return $this->getRequest()->getHttpPartInstance();
97
    }
98
99
    /**
100
     * Returns the URL the client used to make the request.
101
     *
102
     * @return string
103
     */
104
    public function getRequestUrl()
105
    {
106
        return $this->getRequest()->getRequestUrl();
107
    }
108
109
    /**
110
     * Returns the path to the servlet used to handle this request.
111
     *
112
     * @return string The relative path to the servlet
113
     */
114
    public function getServletPath()
115
    {
116
        return $this->getRequest()->getServletPath();
117
    }
118
119
    /**
120
     * Return the session identifier proposed by the actual configuration and request state.
121
     *
122
     * @return string The session identifier proposed for this request
123
     */
124
    public function getProposedSessionId()
125
    {
126
        return $this->getRequest()->getProposedSessionId();
127
    }
128
129
    /**
130
     * Returns the session for this request.
131
     *
132
     * @param boolean $create TRUE to create a new session, else FALSE
133
     *
134
     * @return \AppserverIo\Psr\Servlet\Http\HttpSessionInterface The session instance
135
     */
136
    public function getSession($create = false)
137
    {
138
        return $this->getRequest()->getSession($create);
139
    }
140
141
    /**
142
     * Returns the absolute path info started from the context path.
143
     *
144
     * @return string the absolute path info
145
     */
146
    public function getPathInfo()
147
    {
148
        return $this->getRequest()->getPathInfo();
149
    }
150
151
    /**
152
     * Returns the server name.
153
     *
154
     * @return string The server name
155
     */
156
    public function getServerName()
157
    {
158
        return $this->getRequest()->getServerName();
159
    }
160
161
    /**
162
     * Returns query string of the actual request.
163
     *
164
     * @return string|null The query string of the actual request
165
     */
166 1
    public function getQueryString()
167
    {
168 1
        return $this->getRequest()->getQueryString();
169
    }
170
171
    /**
172
     * Returns header info by given key
173
     *
174
     * @param string $key The header key to get
175
     *
176
     * @return string|null
177
     */
178
    public function getHeader($key)
179
    {
180
        return $this->getRequest()->getHeader($key);
181
    }
182
183
    /**
184
     * Returns headers data.
185
     *
186
     * @return array
187
     */
188
    public function getHeaders()
189
    {
190
        return $this->getRequest()->getHeaders();
191
    }
192
193
    /**
194
     * Returns request method
195
     *
196
     * @return string
197
     */
198
    public function getMethod()
199
    {
200
        return $this->getRequest()->getMethod();
201
    }
202
203
    /**
204
     * Sets the method to be performed on the resource identified by the
205
     * Request-URI.
206
     *
207
     * While HTTP method names are typically all uppercase characters, HTTP
208
     * method names are case-sensitive and thus implementations SHOULD NOT
209
     * modify the given string.
210
     *
211
     * @param string $method Case-insensitive method
212
     *
213
     * @return void
214
     */
215
    public function setMethod($method)
216
    {
217
        $this->getRequest()->setMethod($method);
218
    }
219
220
    /**
221
     * Returns true if the request has a cookie header with the passed
222
     * name, else false.
223
     *
224
     * @param string $cookieName Name of the cookie header to be checked
225
     *
226
     * @return boolean true if the request has the cookie, else false
227
     */
228
    public function hasCookie($cookieName)
229
    {
230
        return $this->getRequest()->hasCookie($cookieName);
231
    }
232
233
    /**
234
     * Returns the value of the cookie with the passed name.
235
     *
236
     * @param string $cookieName The name of the cookie to return
237
     *
238
     * @return \AppserverIo\Psr\HttpMessage\CookieInterface The cookie instance
239
     */
240
    public function getCookie($cookieName)
241
    {
242
        return $this->getRequest()->getCookie($cookieName);
243
    }
244
245
    /**
246
     * Adds the passed cookie to this request.
247
     *
248
     * @param \AppserverIo\Psr\HttpMessage\CookieInterface $cookie The cookie to add
249
     *
250
     * @return void
251
     */
252
    public function addCookie(CookieInterface $cookie)
253
    {
254
        $this->getRequest()->addCookie($cookie);
255
    }
256
257
    /**
258
     * Adds a header information got from connection.
259
     *
260
     * @param string $name  The header name
261
     * @param string $value The headers value
262
     *
263
     * @return void
264
     */
265
    public function addHeader($name, $value)
266
    {
267
        $this->getRequest()->addHeader($name, $value);
268
    }
269
270
    /**
271
     * Adds a part to the parts collection.
272
     *
273
     * @param \AppserverIo\Psr\HttpMessage\PartInterface $part A form part object
274
     * @param string                                     $name A manually defined name
275
     *
276
     * @return void
277
     */
278
    public function addPart(PartInterface $part, $name = null)
279
    {
280
        $this->getRequest()->addPart($part, $name);
281
    }
282
283
    /**
284
     * Returns the body content as string.
285
     *
286
     * @return string The body content
287
     */
288
    public function getBodyContent()
289
    {
290
        return $this->getRequest()->getBodyContent();
291
    }
292
293
    /**
294
     * Returns the body stream as a resource.
295
     *
296
     * @return resource The body stream
297
     */
298
    public function getBodyStream()
299
    {
300
        return $this->getRequest()->getBodyStream();
301
    }
302
303
    /**
304
     * Returns the Http request instance.
305
     *
306
     * @return \AppserverIo\Psr\HttpMessage\RequestInterface The Http request instance
307
     */
308
    public function getHttpRequest()
309
    {
310
        return $this->getRequest()->getHttpRequest();
311
    }
312
313
    /**
314
     * Returns an array with all request parameters.
315
     *
316
     * @return array The array with the request parameters
317
     */
318
    public function getParameterMap()
319
    {
320
        return $this->getRequest()->getParameterMap();
321
    }
322
323
    /**
324
     * Returns the parameter with the passed name if available or null
325
     * if the parameter not exists.
326
     *
327
     * @param string  $name   The name of the parameter to return
328
     * @param integer $filter The filter to use
329
     *
330
     * @return string|null
331
     */
332
    public function getParameter($name, $filter = FILTER_SANITIZE_STRING)
333
    {
334
        return $this->getRequest()->getParameter($name, $filter);
335
    }
336
337
    /**
338
     * Returns a part object by given name
339
     *
340
     * @param string $name The name of the form part
341
     *
342
     * @return \AppserverIo\Psr\HttpMessage\PartInterface The part instance
343
     */
344
    public function getPart($name)
345
    {
346
        return $this->getRequest()->getPart($name);
347
    }
348
349
    /**
350
     * Returns the parts collection as array
351
     *
352
     * @return array A collection of HttpPart objects
353
     */
354
    public function getParts()
355
    {
356
        return $this->getRequest()->getParts();
357
    }
358
359
    /**
360
     * Return the session identifier included in this request, if any.
361
     *
362
     * @return string The session identifier included in this request
363
     */
364
    public function getRequestedSessionId()
365
    {
366
        return $this->getRequest()->getRequestedSessionId();
367
    }
368
369
    /**
370
     * Return the session name included in this request, if any.
371
     *
372
     * @return string The session name included in this request
373
     */
374
    public function getRequestedSessionName()
375
    {
376
        return $this->getRequest()->getRequestedSessionName();
377
    }
378
379
    /**
380
     * Returns the servlet response bound to this request.
381
     *
382
     * @return \AppserverIo\Psr\Servlet\Http\HttpServletResponseInterface The response instance
383
     */
384
    public function getResponse()
385
    {
386
        return $this->getRequest()->getResponse();
387
    }
388
389
    /**
390
     * Returns the server variable with the requested name.
391
     *
392
     * @param string $name The name of the server variable to be returned
393
     *
394
     * @return mixed The requested server variable
395
     */
396
    public function getServerVar($name)
397
    {
398
        return $this->getRequest()->getServerVar($name);
399
    }
400
401
    /**
402
     * Returns the array with the server variables.
403
     *
404
     * @return array The array with the server variables
405
     */
406
    public function getServerVars()
407
    {
408
        return $this->getRequest()->getServerVars();
409
    }
410
411
    /**
412
     * Returns the request URI.
413
     *
414
     * @return string The request URI
415
     */
416
    public function getUri()
417
    {
418
        return $this->getRequest()->getUri();
419
    }
420
421
    /**
422
     * Returns the protocol version.
423
     *
424
     * @return string The protocol version
425
     */
426
    public function getVersion()
427
    {
428
        return $this->getRequest()->getVersion();
429
    }
430
431
    /**
432
     * Checks if header exists by given name.
433
     *
434
     * @param string $name The header name to check
435
     *
436
     * @return boolean
437
     */
438
    public function hasHeader($name)
439
    {
440
        return $this->getRequest()->hasHeader($name);
441
    }
442
443
    /**
444
     * Queries whether the request contains a parameter or not.
445
     *
446
     * @param string $name The name of the param we're query for
447
     *
448
     * @return boolean TRUE if the parameter is available, else FALSE
449
     */
450
    public function hasParameter($name)
451
    {
452
        return $this->getRequest()->hasParameter($name);
453
    }
454
455
    /**
456
     * Sets the flag that shows if the request has already been dispatched.
457
     *
458
     * @return boolean TRUE if the request has already been dispatched, else FALSE
459
     */
460
    public function isDispatched()
461
    {
462
        return $this->getRequest()->isDispatched();
463
    }
464
465
    /**
466
     * Set Base modifier which allows for base path generation within rewritten URL environments.
467
     *
468
     * @param string $baseModifier The base modifier
469
     *
470
     * @return void
471
     */
472
    public function setBaseModifier($baseModifier)
473
    {
474
        $this->getRequest()->setBaseModifier($baseModifier);
475
    }
476
477
    /**
478
     * Resets the stream resource pointing to body content.
479
     *
480
     * @param resource $bodyStream The body content stream resource
481
     *
482
     * @return void
483
     */
484
    public function setBodyStream($bodyStream)
485
    {
486
        $this->getRequest()->setBodyStream($bodyStream);
487
    }
488
489
    /**
490
     * Sets the application context name (application name prefixed with a slash) for the actual request.
491
     *
492
     * @param string $contextPath The application context name
493
     *
494
     * @return void
495
     */
496
    public function setContextPath($contextPath)
497
    {
498
        $this->getRequest()->setContextPath($contextPath);
499
    }
500
501
    /**
502
     * Sets the flag to mark the request dispatched.
503
     *
504
     * @param boolean $dispatched TRUE if the request has already been dispatched, else FALSE
505
     *
506
     * @return void
507
     */
508
    public function setDispatched($dispatched = true)
509
    {
510
        $this->getRequest()->setDispatched($dispatched);
511
    }
512
513
    /**
514
     * Set headers data.
515
     *
516
     * @param array $headers The headers array to set
517
     *
518
     * @return void
519
     */
520
    public function setHeaders(array $headers)
521
    {
522
        $this->getRequest()->setHeaders($headers);
523
    }
524
525
    /**
526
     * Sets an array with all request parameters.
527
     *
528
     * @param array $parameterMap The parameter map
529
     *
530
     * @return void
531
     */
532
    public function setParameterMap(array $parameterMap)
533
    {
534
        $this->getRequest()->setParameterMap($parameterMap);
535
    }
536
537
    /**
538
     * Sets the absolute path info started from the context path.
539
     *
540
     * @param string $pathInfo The path info
541
     *
542
     * @return void
543
     */
544
    public function setPathInfo($pathInfo)
545
    {
546
        $this->getRequest()->setPathInfo($pathInfo);
547
    }
548
549
    /**
550
     * Set the requested session ID for this request. This is normally called by
551
     * the HTTP Connector, when it parses the request headers.
552
     *
553
     * @param string $requestedSessionId The requested session ID
554
     *
555
     * @return void
556
     */
557
    public function setRequestedSessionId($requestedSessionId)
558
    {
559
        $this->getRequest()->setRequestedSessionId($requestedSessionId);
560
    }
561
562
    /**
563
     * Set the requested session name for this request.
564
     *
565
     * @param string $requestedSessionName The requested session name
566
     *
567
     * @return void
568
     */
569
    public function setRequestedSessionName($requestedSessionName)
570
    {
571
        $this->getRequest()->setRequestedSessionName($requestedSessionName);
572
    }
573
574
    /**
575
     * Sets the path to the servlet used to handle this request.
576
     *
577
     * @param string $servletPath The path to the servlet
578
     *
579
     * @return void
580
     */
581
    public function setServletPath($servletPath)
582
    {
583
        $this->getRequest()->setServletPath($servletPath);
584
    }
585
586
    /**
587
     * Sets the URI.
588
     *
589
     * @param string $uri The request URI
590
     *
591
     * @return void
592
     */
593
    public function setUri($uri)
594
    {
595
        $this->getRequest()->setUri($uri);
596
    }
597
598
    /**
599
     * Set the protocol version.
600
     *
601
     * @param string $version The protocol version
602
     *
603
     * @return void
604
     */
605
    public function setVersion($version)
606
    {
607
        $this->getRequest()->setVersion($version);
608
    }
609
}
610