PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.25
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.25
1.10.25 1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 All 169 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / Attributes / AttributeBag.php

AttributeBag.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.25, at vendor_prefixed/sentry/sentry/src/Attributes/AttributeBag.php

63 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\Sentry\Attributes;
5
6 /**
7 * @phpstan-import-type AttributeValue from Attribute
8 */
9 class AttributeBag
10 {
11 /**
12 * @var array<string, Attribute>
13 */
14 private $attributes = [];
15 /**
16 * @param mixed $value
17 */
18 public function set(string $key, $value) : self
19 {
20 $attribute = $value instanceof Attribute ? $value : Attribute::tryFromValue($value);
21 if ($attribute !== null) {
22 $this->attributes[$key] = $attribute;
23 }
24 return $this;
25 }
26 /**
27 * @param mixed $value
28 */
29 public function setUnlessNull(string $key, $value) : void
30 {
31 if ($value !== null) {
32 self::set($key, $value);
33 }
34 }
35 public function get(string $key) : ?Attribute
36 {
37 return $this->attributes[$key] ?? null;
38 }
39 public function forget(string $key) : self
40 {
41 unset($this->attributes[$key]);
42 return $this;
43 }
44 /**
45 * @return array<string, Attribute>
46 */
47 public function all() : array
48 {
49 return $this->attributes;
50 }
51 /**
52 * Get a simplified representation of the attributes as a key-value array, main purpose is for logging output.
53 *
54 * @return array<string, AttributeValue>
55 */
56 public function toSimpleArray() : array
57 {
58 return \array_map(static function (Attribute $attribute) {
59 return $attribute->getValue();
60 }, $this->attributes);
61 }
62 }
63