| 1 | <?php |
||
| 5 | use Illuminate\Support\Arr; |
||
| 6 | |||
| 7 | trait HasCustomProperties |
||
| 8 | { |
||
| 9 | public function hasCustomProperty(string $propertyName): bool |
||
| 10 | { |
||
| 11 | return Arr::has(($this->custom_properties, $propertyName); |
||
|
|
|||
| 12 | } |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param string $propertyName |
||
| 16 | * @param mixed $default |
||
| 17 | * |
||
| 18 | * @return mixed |
||
| 19 | */ |
||
| 20 | public function getCustomProperty(string $propertyName, $default = null) |
||
| 21 | { |
||
| 22 | return Arr::get($this->custom_properties, $propertyName, $default); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $name |
||
| 27 | * @param mixed $value |
||
| 28 | * |
||
| 29 | * @return $this |
||
| 30 | */ |
||
| 31 | public function setCustomProperty(string $name, $value) |
||
| 32 | { |
||
| 33 | $customProperties = $this->custom_properties; |
||
| 34 | |||
| 35 | Arr::set($customProperties, $name, $value); |
||
| 36 | |||
| 37 | $this->custom_properties = $customProperties; |
||
| 38 | |||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $name |
||
| 44 | * |
||
| 45 | * @return $this |
||
| 46 | */ |
||
| 47 | public function forgetCustomProperty(string $name) |
||
| 48 | { |
||
| 49 | $customProperties = $this->custom_properties; |
||
| 50 | |||
| 51 | Arr::forget($customProperties, $name); |
||
| 52 | |||
| 53 | $this->custom_properties = $customProperties; |
||
| 54 | |||
| 55 | return $this; |
||
| 56 | } |
||
| 58 |