1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Fuel\Foundation |
4
|
|
|
* @version 2.0 |
5
|
|
|
* @author Fuel Development Team |
6
|
|
|
* @license MIT License |
7
|
|
|
* @copyright 2010 - 2016 Fuel Development Team |
8
|
|
|
* @link http://fuelphp.com |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Fuel\Foundation\Request; |
12
|
|
|
|
13
|
|
|
use UnexpectedValueException; |
14
|
|
|
use Zend\Diactoros\ServerRequestFactory; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Temporary request factory until fuel has a http message implementation |
18
|
|
|
* |
19
|
|
|
* @package Fuel\Foundation\Request |
20
|
|
|
*/ |
21
|
|
|
class HttpRequestFactory extends ServerRequestFactory |
22
|
|
|
{ |
23
|
6 |
|
public static function fromGlobals( |
24
|
|
|
array $server = null, |
25
|
|
|
array $query = null, |
26
|
|
|
array $body = null, |
27
|
|
|
array $cookies = null, |
28
|
|
|
array $files = null |
29
|
|
|
) { |
30
|
6 |
|
$server = static::normalizeServer($server ?: $_SERVER); |
31
|
6 |
|
$files = static::normalizeFiles($files ?: $_FILES); |
32
|
6 |
|
$headers = static::marshalHeaders($server); |
33
|
|
|
|
34
|
6 |
|
return new Http( |
35
|
|
|
$server, |
36
|
|
|
$files, |
37
|
6 |
|
static::marshalUriFromServer($server, $headers), |
38
|
6 |
|
static::get('REQUEST_METHOD', $server, 'GET'), |
39
|
6 |
|
'php://input', |
40
|
|
|
$headers, |
41
|
6 |
|
$cookies ?: $_COOKIE, |
42
|
6 |
|
$query ?: $_GET, |
43
|
6 |
|
$body ?: $_POST, |
44
|
6 |
|
static::marshalProtocolVersion($server) |
|
|
|
|
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
6 |
|
private static function marshalProtocolVersion(array $server) |
|
|
|
|
50
|
|
|
{ |
51
|
6 |
|
if (! isset($server['SERVER_PROTOCOL'])) { |
52
|
6 |
|
return '1.1'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (! preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) { |
56
|
|
|
throw new UnexpectedValueException(sprintf( |
57
|
|
|
'Unrecognized protocol version (%s)', |
58
|
|
|
$server['SERVER_PROTOCOL'] |
59
|
|
|
)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $matches['version']; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: