Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject a custom Service into a ElasticaToModelTransformer #1889

Open
pl1zahd opened this issue Oct 20, 2022 · 1 comment
Open

Inject a custom Service into a ElasticaToModelTransformer #1889

pl1zahd opened this issue Oct 20, 2022 · 1 comment

Comments

@pl1zahd
Copy link

pl1zahd commented Oct 20, 2022

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!

@SzymonKaminski
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants