You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a question about what approach should I take.
We were using version 0.3.0 of Valinor until now, and we created our custom sources for different classes, but as we are migration to 0.7.0 I found the Mapper/Source classes very useful but I want to ask you if there's anyway I can modify a value of a multidimensional array key to a (array) json_decode($value)
class ClientTimelineTransformationSource implements \IteratorAggregate
{
private array $source = [];
public function __construct(iterable $source)
{
$this->source = $this->transform($source);
}
public array $keyMap = [
'timeline_type' => 'type',
'created_at' => 'createdAt',
'updated_at' => 'updatedAt',
];
private function transform(iterable $source): array
{
$array = [];
foreach ($source as $key => $value) {
if (is_iterable($value)) {
return $this->transform($value);
}
if ($key === 'metadata') {
$array[$key] = json_decode($value, true);
} else {
$array[$this->keyMap[$key] ?? $key] = $value;
}
}
return $array;
}
public function getIterator()
{
yield from $this->source;
}
/**
* @return array
*/
public function getSource(): array
{
return $this->source;
}
}
With this source, I mapped a key to another and CamelCase the other keys, but also, for key metadata I use json_decode to decode a json string, so Valinor can Map metadata into the ClientTimeline.
I was wondering is there any way I can modify the value of the metadata key into (array) json_decode($metadata) with a value modifier or something like it.
Hope this made sense.
Thank you for all your work and for your time.
All the best!
Andrés
The text was updated successfully, but these errors were encountered:
Hi @aiglesiasn, your approach seems to be valid for this usecase, although it makes me think we should probably ship a source modifier that could handle "automatic" json decoding among the input.
Hi Romain!
Thank you for your great work!
I have a question about what approach should I take.
We were using version 0.3.0 of Valinor until now, and we created our custom sources for different classes, but as we are migration to 0.7.0 I found the Mapper/Source classes very useful but I want to ask you if there's anyway I can modify a value of a multidimensional array key to a
(array) json_decode($value)
CONTEXT
ClientTimeline Class constructor:
$metadata
, ClientTimelineMetadata Class constructor:In Valinor 0.3.0 I used this Source:
With this source, I mapped a key to another and CamelCase the other keys, but also, for key
metadata
I use json_decode to decode a json string, so Valinor can Mapmetadata
into the ClientTimeline.For Valinor 0.7.0 I'm using this:
I was wondering is there any way I can modify the value of the
metadata
key into(array) json_decode($metadata)
with a value modifier or something like it.Hope this made sense.
Thank you for all your work and for your time.
All the best!
Andrés
The text was updated successfully, but these errors were encountered: