Repository navigation
Expand file tree
/
Copy pathRepository.php
More file actions
119 lines (106 loc) · 2.6 KB
/
Copy pathRepository.php
File metadata and controls
119 lines (106 loc) · 2.6 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Repository class file.
*
* @package Mantle
*/
namespace Mantle\Config;
use ArrayAccess;
use Mantle\Contracts\Config\Repository as Config_Contract;
use Mantle\Support\Arr;
use Mantle\Support\Mixed_Data;
/**
* Configuration Repository
*
* Used to store configuration items for the application.
*
* @implements ArrayAccess<string, mixed>
*/
class Repository implements ArrayAccess, Config_Contract {
/**
* Constructor.
*
* @param array<string, mixed> $items Configuration items for the repository.
*/
public function __construct( protected array $items = [] ) {
}
/**
* Check if a configuration value exists.
*
* @param string $key Key to get, period-delimited.
*/
public function has( string $key ): bool {
return Arr::has( $this->items, $key );
}
/**
* Retrieve a configuration value.
*
* @param string $key Configuration key to get, period-delimited.
* @param mixed $default Default value, optional.
*/
public function get( string $key, mixed $default = null ): mixed {
return Arr::get( $this->items, $key, $default );
}
/**
* Retrieve a configuration value as Mixed_Data.
*
* @param string $key Configuration key to get, period-delimited.
* @param mixed $default Default value, optional.
*/
public function get_mixed( string $key, mixed $default = null ): Mixed_Data {
return Mixed_Data::of( $this->get( $key, $default ) );
}
/**
* Set a configuration value.
*
* @param array<string, mixed>|string $key Key(s) to set.
* @param mixed $value Value to set.
*/
public function set( array|string $key, mixed $value ): void {
$keys = is_array( $key ) ? $key : [ $key => $value ];
foreach ( $keys as $key => $value ) {
Arr::set( $this->items, $key, $value );
}
}
/**
* Get all configuration values.
*
* @return array<string, array<mixed>>
*/
public function all(): array {
return $this->items;
}
/**
* Check if a offset exists.
*
* @param mixed $offset Offset to retrieve.
*/
public function offsetExists( mixed $offset ): bool {
return $this->has( $offset );
}
/**
* Get an offset.
*
* @param mixed $offset Offset to retrieve.
*/
public function offsetGet( mixed $offset ): mixed {
return $this->get( $offset );
}
/**
* Set an offset.
*
* @param mixed $offset Offset to set.
* @param mixed $value Value to set.
*/
public function offsetSet( mixed $offset, mixed $value ): void {
$this->set( $offset, $value );
}
/**
* Unset an offset.
*
* @param mixed $offset Offset to unset.
*/
public function offsetUnset( mixed $offset ): void {
$this->set( $offset, null );
}
}