Facades
2 years ago
Testing
2 years ago
Traits
2 years ago
AggregateServiceProvider.php
2 years ago
Carbon.php
2 years ago
Composer.php
2 years ago
ConfigurationUrlParser.php
2 years ago
DateFactory.php
2 years ago
Env.php
2 years ago
Fluent.php
2 years ago
HigherOrderTapProxy.php
2 years ago
HtmlString.php
2 years ago
InteractsWithTime.php
2 years ago
Js.php
2 years ago
Manager.php
2 years ago
MessageBag.php
2 years ago
MultipleInstanceManager.php
2 years ago
NamespacedItemResolver.php
2 years ago
Optional.php
2 years ago
Pluralizer.php
2 years ago
ProcessUtils.php
2 years ago
Reflector.php
2 years ago
ServiceProvider.php
2 years ago
Str.php
2 years ago
Stringable.php
2 years ago
Timebox.php
2 years ago
ValidatedInput.php
2 years ago
ViewErrorBag.php
2 years ago
helpers.php
2 years ago
Fluent.php
181 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP_SCOPED\Illuminate\Support; |
| 4 | |
| 5 | use ArrayAccess; |
| 6 | use IAWP_SCOPED\Illuminate\Contracts\Support\Arrayable; |
| 7 | use IAWP_SCOPED\Illuminate\Contracts\Support\Jsonable; |
| 8 | use JsonSerializable; |
| 9 | /** @internal */ |
| 10 | class Fluent implements Arrayable, ArrayAccess, Jsonable, JsonSerializable |
| 11 | { |
| 12 | /** |
| 13 | * All of the attributes set on the fluent instance. |
| 14 | * |
| 15 | * @var array |
| 16 | */ |
| 17 | protected $attributes = []; |
| 18 | /** |
| 19 | * Create a new fluent instance. |
| 20 | * |
| 21 | * @param array|object $attributes |
| 22 | * @return void |
| 23 | */ |
| 24 | public function __construct($attributes = []) |
| 25 | { |
| 26 | foreach ($attributes as $key => $value) { |
| 27 | $this->attributes[$key] = $value; |
| 28 | } |
| 29 | } |
| 30 | /** |
| 31 | * Get an attribute from the fluent instance. |
| 32 | * |
| 33 | * @param string $key |
| 34 | * @param mixed $default |
| 35 | * @return mixed |
| 36 | */ |
| 37 | public function get($key, $default = null) |
| 38 | { |
| 39 | if (\array_key_exists($key, $this->attributes)) { |
| 40 | return $this->attributes[$key]; |
| 41 | } |
| 42 | return \IAWP_SCOPED\value($default); |
| 43 | } |
| 44 | /** |
| 45 | * Get the attributes from the fluent instance. |
| 46 | * |
| 47 | * @return array |
| 48 | */ |
| 49 | public function getAttributes() |
| 50 | { |
| 51 | return $this->attributes; |
| 52 | } |
| 53 | /** |
| 54 | * Convert the fluent instance to an array. |
| 55 | * |
| 56 | * @return array |
| 57 | */ |
| 58 | public function toArray() |
| 59 | { |
| 60 | return $this->attributes; |
| 61 | } |
| 62 | /** |
| 63 | * Convert the object into something JSON serializable. |
| 64 | * |
| 65 | * @return array |
| 66 | */ |
| 67 | #[\ReturnTypeWillChange] |
| 68 | public function jsonSerialize() |
| 69 | { |
| 70 | return $this->toArray(); |
| 71 | } |
| 72 | /** |
| 73 | * Convert the fluent instance to JSON. |
| 74 | * |
| 75 | * @param int $options |
| 76 | * @return string |
| 77 | */ |
| 78 | public function toJson($options = 0) |
| 79 | { |
| 80 | return \json_encode($this->jsonSerialize(), $options); |
| 81 | } |
| 82 | /** |
| 83 | * Determine if the given offset exists. |
| 84 | * |
| 85 | * @param string $offset |
| 86 | * @return bool |
| 87 | */ |
| 88 | #[\ReturnTypeWillChange] |
| 89 | public function offsetExists($offset) |
| 90 | { |
| 91 | return isset($this->attributes[$offset]); |
| 92 | } |
| 93 | /** |
| 94 | * Get the value for a given offset. |
| 95 | * |
| 96 | * @param string $offset |
| 97 | * @return mixed |
| 98 | */ |
| 99 | #[\ReturnTypeWillChange] |
| 100 | public function offsetGet($offset) |
| 101 | { |
| 102 | return $this->get($offset); |
| 103 | } |
| 104 | /** |
| 105 | * Set the value at the given offset. |
| 106 | * |
| 107 | * @param string $offset |
| 108 | * @param mixed $value |
| 109 | * @return void |
| 110 | */ |
| 111 | #[\ReturnTypeWillChange] |
| 112 | public function offsetSet($offset, $value) |
| 113 | { |
| 114 | $this->attributes[$offset] = $value; |
| 115 | } |
| 116 | /** |
| 117 | * Unset the value at the given offset. |
| 118 | * |
| 119 | * @param string $offset |
| 120 | * @return void |
| 121 | */ |
| 122 | #[\ReturnTypeWillChange] |
| 123 | public function offsetUnset($offset) |
| 124 | { |
| 125 | unset($this->attributes[$offset]); |
| 126 | } |
| 127 | /** |
| 128 | * Handle dynamic calls to the fluent instance to set attributes. |
| 129 | * |
| 130 | * @param string $method |
| 131 | * @param array $parameters |
| 132 | * @return $this |
| 133 | */ |
| 134 | public function __call($method, $parameters) |
| 135 | { |
| 136 | $this->attributes[$method] = \count($parameters) > 0 ? $parameters[0] : \true; |
| 137 | return $this; |
| 138 | } |
| 139 | /** |
| 140 | * Dynamically retrieve the value of an attribute. |
| 141 | * |
| 142 | * @param string $key |
| 143 | * @return mixed |
| 144 | */ |
| 145 | public function __get($key) |
| 146 | { |
| 147 | return $this->get($key); |
| 148 | } |
| 149 | /** |
| 150 | * Dynamically set the value of an attribute. |
| 151 | * |
| 152 | * @param string $key |
| 153 | * @param mixed $value |
| 154 | * @return void |
| 155 | */ |
| 156 | public function __set($key, $value) |
| 157 | { |
| 158 | $this->offsetSet($key, $value); |
| 159 | } |
| 160 | /** |
| 161 | * Dynamically check if an attribute is set. |
| 162 | * |
| 163 | * @param string $key |
| 164 | * @return bool |
| 165 | */ |
| 166 | public function __isset($key) |
| 167 | { |
| 168 | return $this->offsetExists($key); |
| 169 | } |
| 170 | /** |
| 171 | * Dynamically unset an attribute. |
| 172 | * |
| 173 | * @param string $key |
| 174 | * @return void |
| 175 | */ |
| 176 | public function __unset($key) |
| 177 | { |
| 178 | $this->offsetUnset($key); |
| 179 | } |
| 180 | } |
| 181 |