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.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / ecommerce / PaymentGateways / Paypal / src / Config / Repository.php
tutor / ecommerce / PaymentGateways / Paypal / src / Config Last commit date
Repository.php 1 year ago
Repository.php
170 lines
1 <?php
2
3 namespace Ollyo\PaymentHub\Config;
4
5 use ArrayAccess;
6 use Ollyo\PaymentHub\Contracts\Config\RepositoryContract;
7
8 class Repository implements ArrayAccess, RepositoryContract
9 {
10 /**
11 * All the configuration items
12 *
13 * @var array
14 */
15 protected $items = [];
16
17 public function __construct(array $items = [])
18 {
19 $this->items = $items;
20 }
21
22 /**
23 * Determine if a key exists in the repository
24 *
25 * @param mixed $key
26 * @return boolean
27 */
28 public function has($key): bool
29 {
30 return isset($this->items[$key]);
31 }
32
33 /**
34 * Get the value from the repository using a key, if not found then return the default value.
35 *
36 * @param mixed $key
37 * @param mixed $default
38 * @return mixed
39 */
40 public function get($key, $default = null)
41 {
42 if (is_array($key)) {
43 return $this->getMany($key);
44 }
45
46 if (!$this->has($key)) {
47 return $default;
48 }
49
50 return $this->items[$key];
51 }
52
53 public function getMany(array $keys)
54 {
55 $config = [];
56
57 foreach ($keys as $key => $default) {
58 if (is_numeric($key)) {
59 [$key, $default] = [$default, null];
60 }
61
62 $config[$key] = $this->get($key, $default);
63 }
64
65 return $config;
66 }
67
68 /**
69 * Set a value to the repository by the key. This is for updating an existing value or add new.
70 *
71 * @param mixed $key
72 * @param mixed $value
73 * @return void
74 */
75 public function set($key, $value = null)
76 {
77 $keys = is_array($key) ? $key: [$key => $value];
78
79 foreach ($keys as $key => $value) {
80 $this->items[$key] = $value;
81 }
82 }
83
84 /**
85 * Get all the values
86 *
87 * @return array
88 */
89 public function all()
90 {
91 return $this->items;
92 }
93
94 /**
95 * Prepend to the repository
96 *
97 * @param mixed $key
98 * @param mixed $value
99 * @return void
100 */
101 public function prepend($key, $value)
102 {
103 $array = $this->get($key, []);
104
105 array_unshift($array, $value);
106
107 $this->set($key, $array);
108 }
109
110 /**
111 * Append to the repository
112 *
113 * @param mixed $key
114 * @param mixed $value
115 * @return void
116 */
117 public function push($key, $value)
118 {
119 $array = $this->get($key, []);
120
121 array_push($array, $value);
122
123 $this->set($key, $array);
124 }
125
126 /**
127 * Check if the configuration option exists.
128 *
129 * @param string $key
130 * @return bool
131 */
132 public function offsetExists($key): bool
133 {
134 return $this->has($key);
135 }
136
137 /**
138 * Get the value by the key
139 *
140 * @param string $key
141 * @return mixed
142 */
143 public function offsetGet($key): mixed
144 {
145 return $this->get($key);
146 }
147
148 /**
149 * Set value by offset key
150 *
151 * @param string $key
152 * @param mixed $value
153 * @return void
154 */
155 public function offsetSet($key, $value): void
156 {
157 $this->set($key, $value);
158 }
159
160 /**
161 * Unset a value by setting it by null
162 *
163 * @param string $key
164 * @return void
165 */
166 public function offsetUnset($key): void
167 {
168 $this->set($key, null);
169 }
170 }