PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.6
Kubio AI Page Builder v2.8.6
2.9.0 2.8.6 2.8.5 2.8.4 2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / vendor / pragmarx / ia-str / src / Support / Optional.php
kubio / vendor / pragmarx / ia-str / src / Support Last commit date
Traits 1 year ago Arr.php 4 years ago Carbon.php 4 years ago Collection.php 1 year ago Enumerable.php 4 years ago HigherOrderCollectionProxy.php 4 years ago HigherOrderTapProxy.php 4 years ago HtmlString.php 4 years ago LazyCollection.php 4 years ago Optional.php 4 years ago Pluralizer.php 4 years ago Str.php 1 year ago alias.php 4 years ago helpers.php 4 years ago
Optional.php
131 lines
1 <?php
2
3 namespace IlluminateAgnostic\Str\Support;
4
5 use ArrayAccess;
6 use ArrayObject;
7
8 class Optional implements ArrayAccess
9 {
10 use Traits\Macroable {
11 __call as macroCall;
12 }
13
14 /**
15 * The underlying object.
16 *
17 * @var mixed
18 */
19 protected $value;
20
21 /**
22 * Create a new optional instance.
23 *
24 * @param mixed $value
25 * @return void
26 */
27 public function __construct($value)
28 {
29 $this->value = $value;
30 }
31
32 /**
33 * Dynamically access a property on the underlying object.
34 *
35 * @param string $key
36 * @return mixed
37 */
38 public function __get($key)
39 {
40 if (is_object($this->value)) {
41 return $this->value->{$key} ?? null;
42 }
43 }
44
45 /**
46 * Dynamically check a property exists on the underlying object.
47 *
48 * @param mixed $name
49 * @return bool
50 */
51 public function __isset($name)
52 {
53 if (is_object($this->value)) {
54 return isset($this->value->{$name});
55 }
56
57 if (is_array($this->value) || $this->value instanceof ArrayObject) {
58 return isset($this->value[$name]);
59 }
60
61 return false;
62 }
63
64 /**
65 * Determine if an item exists at an offset.
66 *
67 * @param mixed $key
68 * @return bool
69 */
70 public function offsetExists($key)
71 {
72 return Arr::accessible($this->value) && Arr::exists($this->value, $key);
73 }
74
75 /**
76 * Get an item at a given offset.
77 *
78 * @param mixed $key
79 * @return mixed
80 */
81 public function offsetGet($key)
82 {
83 return Arr::get($this->value, $key);
84 }
85
86 /**
87 * Set the item at a given offset.
88 *
89 * @param mixed $key
90 * @param mixed $value
91 * @return void
92 */
93 public function offsetSet($key, $value)
94 {
95 if (Arr::accessible($this->value)) {
96 $this->value[$key] = $value;
97 }
98 }
99
100 /**
101 * Unset the item at a given offset.
102 *
103 * @param string $key
104 * @return void
105 */
106 public function offsetUnset($key)
107 {
108 if (Arr::accessible($this->value)) {
109 unset($this->value[$key]);
110 }
111 }
112
113 /**
114 * Dynamically pass a method to the underlying object.
115 *
116 * @param string $method
117 * @param array $parameters
118 * @return mixed
119 */
120 public function __call($method, $parameters)
121 {
122 if (static::hasMacro($method)) {
123 return $this->macroCall($method, $parameters);
124 }
125
126 if (is_object($this->value)) {
127 return $this->value->{$method}(...$parameters);
128 }
129 }
130 }
131