FOSElasticaBundle
FOSElasticaBundle copied to clipboard
Inject a custom Service into a ElasticaToModelTransformer
Hi,
first up, thanks for creating and maintaining such a wonderful piece of software!
I use the Doctrine ORM driver for my project in combination with Version 6.2.0 of this bundle. I have a use-case where it would be useful for me have another Service to be injected into a custom ElasticaToModelTransformer.
When I add no additional Services, I can already use my custom Transformer, but whenever I try to add another Service into the Constructor, it seems that the Index ist not registered in the RepositoryManager.
Every way I tried so far ended either with the Message No repository is configured for index "objects".
I've already tried to extend FOS\ElasticaBundle\Transformer\AbstractElasticaToModelTransformer, FOS\ElasticaBundle\Doctrine\AbstractElasticaToModelTransformer and to just implement the FOS\ElasticaBundle\Transformer\ElasticaToModelTransformerInterface.
Here is my configuration:
fos_elastica:
clients:
default: { url: 'http://elasticsearch:9200/' }
indexes:
objects:
persistence:
driver: orm #the driver can be orm, mongodb or phpcr
model: ACME\Entity\ACMEObject
model_to_elastica_transformer:
service: ACME\Transformer\ACMEObjectModelToElasticaTransformer
elastica_to_model_transformer:
service: ACME\Transformer\ElasticaToACMEObjectModelTransformer
persister:
service: ACME\Persister\ObjectPersister
listener:
logger: true
Is it just not possible to add another Service via autowire / autoconfigure or do I have to decorate a service to overwrite the parameters?
If any information is missing that you need to have, let me know and I will update my question accordingly.
Thanks for any help in advance!
Not sure if it is the only way, but I've just used setter injection
class CategoryTransformer extends ElasticaToModelTransformer
{
private IriConverterInterface $iriConverter;
public function setIriConverter(IriConverterInterface $iriConverter): void
{
$this->iriConverter = $iriConverter;
}
and
CategoryTransformer:
calls:
- setPropertyAccessor:
- "@fos_elastica.property_accessor"
- setIriConverter:
- "@api_platform.symfony.iri_converter"