deprecated: try to magically resolve constructor

This commit is contained in:
icefox 2026-02-18 19:32:14 -03:00
parent aa7b062b29
commit bef42b3352
No known key found for this signature in database
3 changed files with 6 additions and 9 deletions

View file

@ -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

View file

@ -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
{ {

View file

@ -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' => [