Middleware no longer takes a Pipeline.
[hoplite.git] / http2 / request.php
1 <?php
2 // Hoplite
3 // Copyright (c) 2016 Blue Static
4 //
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
16
17 namespace hoplite\http2;
18
19 /*!
20 A Request represents a HTTP request and holds the data and context associated
21 with it.
22 */
23 class Request
24 {
25 /*! @var string The request method (upper case). */
26 public $http_method = NULL;
27
28 /*! @var string The URL, relataive to the RootController. */
29 public $url = '';
30
31 /*! @var array HTTP request data. */
32 public $data = [];
33
34 /*! @var array Context data. */
35 public $context = [];
36
37 /*!
38 Constructor. Takes an optional URL.
39 */
40 public function __construct($url='')
41 {
42 $this->url = $url;
43 }
44
45 /*!
46 Wrapper around filter_input() that stores the result in the ::$data field.
47 */
48 public function filter($type, $name, $filter=FILTER_SANITIZE_STRING, $options=NULL)
49 {
50 $rv = filter_input($type, $name, $filter, $options);
51 $this->data[$name] = $rv;
52 return $rv;
53 }
54
55 /*!
56 Wrapper around filter_input() that merges the result in the ::$data field.
57 */
58 public function filterArray($type, $definition, $add_empty=TRUE)
59 {
60 $rv = filter_input_array($type, $definition, $add_empty);
61 $this->data = array_merge($this->data, $rv);
62 return $rv;
63 }
64 }