|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Container.php |
|
5
|
|
|
* |
|
6
|
|
|
* This is the internal storage container for test suites. |
|
7
|
|
|
* |
|
8
|
|
|
* PHP version 7.4 |
|
9
|
|
|
* |
|
10
|
|
|
* @category Core |
|
11
|
|
|
* @package RedboxTestSuite |
|
12
|
|
|
* @author Johnny Mast <[email protected]> |
|
13
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
14
|
|
|
* @link https://github.com/johnnymast/redbox-testsuite |
|
15
|
|
|
* @since 1.0 |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace Redbox\Testsuite; |
|
19
|
|
|
|
|
20
|
|
|
use Redbox\Testsuite\Interfaces\ContainerInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class Container |
|
24
|
|
|
* |
|
25
|
|
|
* @package Redbox\Testsuite |
|
26
|
|
|
*/ |
|
27
|
|
|
class Container implements ContainerInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Internal storage for the container. |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected array $storage = []; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Check to see if any information has been stored in the |
|
38
|
|
|
* container using the provided key. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $key The identification key. |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
|
|
public function has(string $key): bool |
|
45
|
|
|
{ |
|
46
|
|
|
return isset($this->storage[$key]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Return a value from the container with a key. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $key The identification key. |
|
53
|
|
|
* |
|
54
|
|
|
* @return mixed|bool |
|
55
|
|
|
*/ |
|
56
|
|
|
public function get(string $key) |
|
57
|
|
|
{ |
|
58
|
|
|
if ($this->has($key)) { |
|
59
|
|
|
return $this->storage[$key]; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Store a value in the container indicated by this key. |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $key The identification key. |
|
69
|
|
|
* @param mixed $value The value for the $key. |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
public function set(string $key, $value): void |
|
74
|
|
|
{ |
|
75
|
|
|
if (!is_null($key)) { |
|
|
|
|
|
|
76
|
|
|
$this->storage[$key] = $value; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Forget a value in the container by this key. |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $key The key to forget. |
|
84
|
|
|
* |
|
85
|
|
|
* @return void |
|
86
|
|
|
*/ |
|
87
|
|
|
public function forget(string $key): void |
|
88
|
|
|
{ |
|
89
|
|
|
if ($this->has($key)) { |
|
90
|
|
|
unset($this->storage[$key]); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|