composer package updates
[openemr.git] / vendor / illuminate / support / Optional.php
blob8f35221ad2c0edd421c9eb596cb66abfa220f2c1
1 <?php
3 namespace Illuminate\Support;
5 use ArrayAccess;
7 class Optional implements ArrayAccess
9 use Traits\Macroable {
10 __call as macroCall;
13 /**
14 * The underlying object.
16 * @var mixed
18 protected $value;
20 /**
21 * Create a new optional instance.
23 * @param mixed $value
24 * @return void
26 public function __construct($value)
28 $this->value = $value;
31 /**
32 * Dynamically access a property on the underlying object.
34 * @param string $key
35 * @return mixed
37 public function __get($key)
39 if (is_object($this->value)) {
40 return $this->value->{$key};
44 /**
45 * Dynamically pass a method to the underlying object.
47 * @param string $method
48 * @param array $parameters
49 * @return mixed
51 public function __call($method, $parameters)
53 if (static::hasMacro($method)) {
54 return $this->macroCall($method, $parameters);
57 if (is_object($this->value)) {
58 return $this->value->{$method}(...$parameters);
62 /**
63 * Determine if an item exists at an offset.
65 * @param mixed $key
66 * @return bool
68 public function offsetExists($key)
70 return Arr::accessible($this->value) && Arr::exists($this->value, $key);
73 /**
74 * Get an item at a given offset.
76 * @param mixed $key
77 * @return mixed
79 public function offsetGet($key)
81 return Arr::get($this->value, $key);
84 /**
85 * Set the item at a given offset.
87 * @param mixed $key
88 * @param mixed $value
89 * @return void
91 public function offsetSet($key, $value)
93 if (Arr::accessible($this->value)) {
94 $this->value[$key] = $value;
98 /**
99 * Unset the item at a given offset.
101 * @param string $key
102 * @return void
104 public function offsetUnset($key)
106 if (Arr::accessible($this->value)) {
107 unset($this->value[$key]);