Skip to content

Commit

Permalink
add json strings mapping to collections
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Oct 23, 2023
1 parent 8864151 commit ea9689a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"php": "^8.1 || ^8.2",
"illuminate/http": "^9.0 || ^10.0",
"illuminate/support": "^9.0 || ^10.0",
"open-southeners/laravel-helpers": "^0.12",
"phpdocumentor/reflection-docblock": "^5.3",
"symfony/property-info": "^6.0"
},
Expand Down
16 changes: 11 additions & 5 deletions src/PropertiesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
use Symfony\Component\PropertyInfo\Type;

use function OpenSoutheners\LaravelHelpers\Strings\is_json_structure;

/**
* The idea here is to leave DataTransferObject class without any properties that
* could harm developers experience with the package.
Expand Down Expand Up @@ -282,11 +284,15 @@ protected function mapIntoCollection(array $propertyTypes, string $propertyKey,
return $value;
}

$collection = Collection::make(
is_array($value)
? $value
: explode(',', $value)
);
if (is_json_structure($value)) {
$collection = Collection::make(json_decode($value, true));
} else {
$collection = Collection::make(
is_array($value)
? $value
: explode(',', $value)
);
}

$collectionTypes = $propertyType->getCollectionValueTypes();

Expand Down

0 comments on commit ea9689a

Please sign in to comment.