|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Shieldon package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Terry L. <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* php version 7.1.0 |
|
11
|
|
|
* |
|
12
|
|
|
* @category Web-security |
|
13
|
|
|
* @package Shieldon |
|
14
|
|
|
* @author Terry Lin <[email protected]> |
|
15
|
|
|
* @copyright 2019 terrylinooo |
|
16
|
|
|
* @license https://github.com/terrylinooo/shieldon/blob/2.x/LICENSE MIT |
|
17
|
|
|
* @link https://github.com/terrylinooo/shieldon |
|
18
|
|
|
* @see https://shieldon.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
declare(strict_types=1); |
|
22
|
|
|
|
|
23
|
|
|
namespace Shieldon\Firewall; |
|
24
|
|
|
|
|
25
|
|
|
use Shieldon\Firewall\Utils\Collection; |
|
26
|
|
|
use Shieldon\Firewall\Utils\Session; |
|
27
|
|
|
use Shieldon\Psr17\ResponseFactory; |
|
28
|
|
|
use Shieldon\Psr17\ServerRequestFactory; |
|
29
|
|
|
use Shieldon\Psr17\StreamFactory; |
|
30
|
|
|
use Shieldon\Psr7\Response; |
|
31
|
|
|
use Shieldon\Psr7\ServerRequest; |
|
32
|
|
|
use Shieldon\Psr7\Stream; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* An object-oriented layer for the HTTP specification. |
|
36
|
|
|
*/ |
|
37
|
|
|
class HttpFactory |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* Create a server-side request. |
|
41
|
|
|
* |
|
42
|
|
|
* @return ServerRequest |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function createRequest(): ServerRequest |
|
45
|
|
|
{ |
|
46
|
|
|
return ServerRequestFactory::fromGlobal(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create a server-side response |
|
51
|
|
|
* |
|
52
|
|
|
* @return Response |
|
53
|
|
|
*/ |
|
54
|
|
|
public static function createResponse(): Response |
|
55
|
|
|
{ |
|
56
|
|
|
return ResponseFactory::fromNew(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Create a server-side response |
|
61
|
|
|
* |
|
62
|
|
|
* @return Stream |
|
63
|
|
|
*/ |
|
64
|
|
|
public static function createStream(): Stream |
|
65
|
|
|
{ |
|
66
|
|
|
return StreamFactory::fromNew(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Create a Session collection from superglobal. |
|
71
|
|
|
* This method is not a PSR-7 pattern. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $id Session ID |
|
74
|
|
|
* |
|
75
|
|
|
* @return Collection |
|
76
|
|
|
*/ |
|
77
|
|
|
public static function createSession($id = ''): Collection |
|
78
|
|
|
{ |
|
79
|
|
|
$session = new Session($id); |
|
80
|
|
|
|
|
81
|
|
|
return $session->createFromGlobal(); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|