- Still working on SearchRequest for optimized and more advanced query manipulations
- Minor bugfixes in DatasetHandler and ObjectInstanciator
This commit is contained in:
1 parent
5d32d9f635
commit
709ed63323
5 files changed
+71
-34
No files matched your search
@@ -78,7 +78,6 @@ class DatasetHandler
|
||||
}
|
||||
}
|
||||
elseif ( EntityField::isScalarType($type->type) ) {
|
||||
|
||||
if ( $type->type === 'string' ) {
|
||||
$attribute = $this->entityResolver->searchFieldAnnotation($field->name, [ Field::class ] );
|
||||
|
||||
@@ -102,8 +101,10 @@ class DatasetHandler
|
||||
try {
|
||||
yield $field->name => Ulmus::instanciateObject($type->type, [ $value ]);
|
||||
}
|
||||
catch(\Error $e) {
|
||||
throw new \Error(sprintf("%s for class '%s' on field '%s'", $e->getMessage(), get_class($this), $field->name));
|
||||
catch(\Throwable $e) {
|
||||
$type = $e::class;
|
||||
|
||||
throw new $type(sprintf("%s for class '%s' on field '%s'", $e->getMessage(), get_class($this), $field->name), 101, $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,22 +5,43 @@ namespace Ulmus\Entity;
|
||||
class ObjectInstanciator {
|
||||
|
||||
protected array $objectCallbackDefinition;
|
||||
|
||||
|
||||
public function instanciate(string $type, array $arguments) : object
|
||||
{
|
||||
if ( isset($this->objectCallbackDefinition[$type]) ) {
|
||||
if (is_object($arguments[0]) && is_a($arguments[0], $type)) {
|
||||
return $arguments[0];
|
||||
}
|
||||
elseif ( isset($this->objectCallbackDefinition[$type]) ) {
|
||||
return $this->objectCallbackDefinition[$type](...$arguments);
|
||||
}
|
||||
elseif ( ($obj = new $type() ) instanceof EntityObjectInterface ) {
|
||||
return $obj->load(...$arguments);
|
||||
}
|
||||
elseif ( ($obj = new $type() ) instanceof JsonUnserializable ) {
|
||||
$obj->jsonUnserialize(json_decode($arguments[0], true));
|
||||
|
||||
return $obj;
|
||||
}
|
||||
else {
|
||||
return new $type(...$arguments);
|
||||
$reflect = new \ReflectionClass($type);
|
||||
|
||||
if ( is_a($type, EntityObjectInterface::class, true) ) {
|
||||
try {
|
||||
$obj = $reflect->newInstance();
|
||||
}
|
||||
catch(\Throwable $t) {
|
||||
$obj = $reflect->newInstanceWithoutConstructor();
|
||||
}
|
||||
|
||||
return $obj->load(...$arguments);
|
||||
}
|
||||
elseif ( is_a($type, JsonUnserializable::class, true)) {
|
||||
try {
|
||||
$obj = $reflect->newInstance();
|
||||
}
|
||||
catch(\Throwable $t) {
|
||||
$obj = $reflect->newInstanceWithoutConstructor();
|
||||
}
|
||||
|
||||
$obj->jsonUnserialize(json_decode($arguments[0], true));
|
||||
|
||||
return $obj;
|
||||
}
|
||||
else {
|
||||
return new $type(...$arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user