1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author : Jagepard <[email protected]"> |
7
|
|
|
* @copyright Copyright (c) 2019, Jagepard |
8
|
|
|
* @license https://mit-license.org/ MIT |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Rudra\Container; |
12
|
|
|
|
13
|
|
|
use Rudra\Container\Interfaces\{ContainerInterface, RequestInterface}; |
14
|
|
|
|
15
|
|
|
class Request implements RequestInterface |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private $instances = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @return ContainerInterface |
24
|
|
|
*/ |
25
|
|
|
public function get(): ContainerInterface |
26
|
|
|
{ |
27
|
|
|
return $this->instantiate('get', Container::class, $_GET); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return ContainerInterface |
32
|
|
|
*/ |
33
|
|
|
public function post(): ContainerInterface |
34
|
|
|
{ |
35
|
|
|
return $this->instantiate('post', Container::class, $_POST); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return ContainerInterface |
40
|
|
|
*/ |
41
|
|
|
public function put(): ContainerInterface |
42
|
|
|
{ |
43
|
|
|
return $this->instantiate('put', Container::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return ContainerInterface |
48
|
|
|
*/ |
49
|
|
|
public function patch(): ContainerInterface |
50
|
|
|
{ |
51
|
|
|
return $this->instantiate('patch', Container::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return ContainerInterface |
56
|
|
|
*/ |
57
|
|
|
public function delete(): ContainerInterface |
58
|
|
|
{ |
59
|
|
|
return $this->instantiate('delete', Container::class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return ContainerInterface |
64
|
|
|
*/ |
65
|
|
|
public function server(): ContainerInterface |
66
|
|
|
{ |
67
|
|
|
return $this->instantiate('server', Container::class, $_SERVER); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return Files |
72
|
|
|
*/ |
73
|
|
|
public function files(): Files |
74
|
|
|
{ |
75
|
|
|
return $this->instantiate('files', Files::class, $_FILES); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param $varName |
80
|
|
|
* @param $instance |
81
|
|
|
* @param $data |
82
|
|
|
* @return mixed |
83
|
|
|
*/ |
84
|
|
|
private function instantiate($varName, $instance, $data = null) |
85
|
|
|
{ |
86
|
|
|
if (!array_key_exists($varName, $this->instances)) { |
87
|
|
|
$this->instances[$varName] = new $instance($data); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $this->instances[$varName]; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|