Add support for toString/Serializable

This commit is contained in:
Philipp 2023-01-21 17:19:35 +01:00
parent 5a9e9cc41b
commit 9627af924a
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
4 changed files with 93 additions and 4 deletions

View file

@ -214,6 +214,17 @@ class ConfigFileTransformer
case "NULL":
return "null";
case "object":
if (method_exists($value, '__toString')) {
return sprintf('\'%s\'', $value);
} elseif ($value instanceof \Serializable) {
try {
return $value->serialize();
} catch (\Exception $e) {
throw new \InvalidArgumentException(sprintf('Cannot serialize %s.', gettype($value)), $e);
}
} else {
throw new \InvalidArgumentException(sprintf('%s is an object without stringify.', gettype($value)));
}
case "resource":
case "resource (closed)":
throw new \InvalidArgumentException(sprintf('%s in configs are not supported yet.', gettype($value)));