I use automapper component (https://jane.readthedocs.io/en/latest/components/AutoMapper.html)
My source can have array properties with keys and values not known in advance. In the example below for example the title of a document in several languages ['fr' => 'Mon titre', 'en' => 'My title']; Is it possible to set dynamic properties to the target (target is an array) as
$target[title_fr] => Mon titre; $target[title_en] => My title;
I was wondering if we could write something like below (it doesn’t work of course) with this type of library:
class SolrDocumentMapperConfiguration implements MapperConfigurationInterface
{
public function getSource(): string
{
return Content::class;
}
public function getTarget(): string
{
return 'array';
}
/**
* @param MapperMetadata $metadata
*/
public function process(MapperGeneratorMetadataInterface $metadata): void
{
$metadata->forMember('rank', static fn (Content $content) => $content->getRank());
$metadata->forMember('title_'.$keyLang, fn (Content $content) {
foreach ($content->getTitles() as $keyLang => $titleLang)
return $titleLang;
}
}
}
Thanks in advance for any help.