Add JSON type support in object property handling
- Added `json` to the list of valid types for object properties. - Implemented JSON decoding for column values when the type is `json`.
This commit is contained in:
@@ -51,7 +51,7 @@ class object_property
|
||||
throw new \InvalidArgumentException("Table or column cannot be empty");
|
||||
}
|
||||
// Check if the type is valid
|
||||
if (!in_array($this->type, ['int', 'varchar', 'text', 'date', 'datetime', 'string', 'timestamp', 'boolean', 'bool', 'float'])) {
|
||||
if (!in_array($this->type, ['int', 'varchar', 'text', 'date', 'datetime', 'string', 'timestamp', 'boolean', 'bool', 'float', 'json'])) {
|
||||
throw new \InvalidArgumentException("Invalid type: $this->type");
|
||||
}
|
||||
$sql = "SELECT $this->column FROM $this->table WHERE id = $this->id";
|
||||
@@ -60,6 +60,11 @@ class object_property
|
||||
if (empty($row)) {
|
||||
throw new \RuntimeException("No record found for column '$this->column' in table '$this->table' with ID $this->id");
|
||||
}
|
||||
// If the type is set to json, decode it.
|
||||
$value = $row[$this->column];
|
||||
if ($this->type === 'json' && $value !== null) {
|
||||
return json_decode($value, true);
|
||||
}
|
||||
return $row[$this->column];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user