Added subscribe method

This commit is contained in:
Alex
2025-07-08 21:46:04 +03:00
parent 45020eab52
commit b997fa17ab
6 changed files with 137 additions and 3 deletions
+20 -1
View File
@@ -16,6 +16,25 @@ abstract readonly class AbstractModel
*/
public function toArray(): array
{
return get_object_vars($this);
return array_map(function ($value) {
return $this->convertValue($value);
}, get_object_vars($this));
}
private function convertValue(mixed $value): mixed
{
if ($value instanceof AbstractModel) {
return $value->toArray();
}
if (is_array($value)) {
return array_map([$this, 'convertValue'], $value);
}
if ($value instanceof \BackedEnum) {
return $value->value;
}
return $value;
}
}