1 | <?php |
||
10 | class ServerRequestFactory |
||
11 | { |
||
12 | use HelperTrait; |
||
13 | |||
14 | /** @var \Wandu\Http\Factory\UploadedFileFactory */ |
||
15 | protected $fileFactory; |
||
16 | |||
17 | /** |
||
18 | * @param \Wandu\Http\Factory\UploadedFileFactory $fileFactory |
||
19 | */ |
||
20 | 17 | public function __construct(UploadedFileFactory $fileFactory) |
|
24 | |||
25 | /** |
||
26 | * @return \Psr\Http\Message\ServerRequestInterface |
||
27 | */ |
||
28 | 1 | public function createFromGlobals() |
|
29 | { |
||
30 | 1 | return $this->create($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES, new PhpInputStream()); |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * @param string $body |
||
35 | * @return \Psr\Http\Message\ServerRequestInterface |
||
36 | */ |
||
37 | 1 | public function createFromSocketBody($body) |
|
46 | |||
47 | /** |
||
48 | * @param array $server |
||
49 | * @param array $get |
||
50 | * @param array $post |
||
51 | * @param array $cookies |
||
52 | * @param array $files |
||
53 | * @param \Psr\Http\Message\StreamInterface $stream |
||
54 | * @return \Psr\Http\Message\ServerRequestInterface |
||
55 | */ |
||
56 | 17 | public function create( |
|
98 | |||
99 | /** |
||
100 | * Parse plain headers. |
||
101 | * |
||
102 | * @param array $plainHeaders |
||
103 | * @return array |
||
104 | */ |
||
105 | 1 | protected function getPhpServerValuesFromPlainHeader(array $plainHeaders) |
|
119 | |||
120 | /** |
||
121 | * @param array $server |
||
122 | * @return \Wandu\Http\Psr\Uri |
||
123 | */ |
||
124 | 17 | protected function getUri(array $server) |
|
133 | |||
134 | /** |
||
135 | * @param array $server |
||
136 | * @return string |
||
137 | */ |
||
138 | 5 | protected function getScheme(array $server) |
|
146 | |||
147 | /** |
||
148 | * @param array $server |
||
149 | * @return string |
||
150 | */ |
||
151 | 17 | protected function getHostAndPort(array $server) |
|
165 | |||
166 | /** |
||
167 | * @param array $server |
||
168 | * @return string |
||
169 | */ |
||
170 | 17 | protected function getRequestUri(array $server) |
|
177 | } |
||
178 |
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: