deprecated: try to magically resolve constructor
This commit is contained in:
parent
aa7b062b29
commit
bef42b3352
3 changed files with 6 additions and 9 deletions
|
|
@ -24,11 +24,13 @@ class ValueFactory
|
||||||
return $mapper($rawValue);
|
return $mapper($rawValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($rawValue)) {
|
// Plain values or numeric arrays are passed as a single parameter to the constructor
|
||||||
return App::makeWith($className, $rawValue);
|
if (!is_array($rawValue) || array_key_exists(0, $rawValue)) {
|
||||||
|
return new $className($className);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new $className($rawValue);
|
// Associative arrays leverage Laravel service container
|
||||||
|
return App::makeWith($className, $rawValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function resolveTypedValue(mixed $rawValue, Type $type): mixed
|
public static function resolveTypedValue(mixed $rawValue, Type $type): mixed
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Tests\Classes;
|
namespace Tests\Classes;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use Icefox\DTO\DataObject;
|
use Icefox\DTO\DataObject;
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
|
|
||||||
readonly class ObjectWithoutMapper
|
readonly class ObjectWithoutMapper
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -198,11 +198,6 @@ test('failed validation throws ValidationException', function () {
|
||||||
})->throws(ValidationException::class);
|
})->throws(ValidationException::class);
|
||||||
|
|
||||||
|
|
||||||
test('tries to resolve without mapper', function () {
|
|
||||||
$object = ObjectWithoutMapper::fromArray(['date' => '1990-04-01']);
|
|
||||||
expect($object->date->isSameDay('1990-04-01'))->toBeTrue();
|
|
||||||
})->group('object-without-mapper');
|
|
||||||
|
|
||||||
test('creates collection', function () {
|
test('creates collection', function () {
|
||||||
$object = CollectionDataObject::fromArray([
|
$object = CollectionDataObject::fromArray([
|
||||||
'values' => [
|
'values' => [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue