-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContext.php
More file actions
40 lines (30 loc) · 820 Bytes
/
Context.php
File metadata and controls
40 lines (30 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace SonsOfPHP\Component\FeatureToggle;
use SonsOfPHP\Contract\FeatureToggle\ContextInterface;
/**
* @author Joshua Estes <joshua@sonsofphp.com>
*/
final class Context implements ContextInterface
{
public function __construct(private array $data = []) {}
public function get(?string $key = null, mixed $default = null): mixed
{
if (null === $key) {
return $this->data;
}
if (!$this->has($key)) {
return $default;
}
return $this->data[$key];
}
public function set(string $key, mixed $value): ContextInterface
{
$this->data[$key] = $value;
return $this;
}
public function has(string $key): bool
{
return \array_key_exists($key, $this->data);
}
}