azzaze
azzaze

Reputation: 151

Symfony 4 - Convert XML to YAML

I'm trying to install FosMessageBundle, without FosUserBundle.

For that, in the doc, we have to create a new service and use it into our services.yaml file

But in the doc, their declaration is in XML, and I can't translate him to YAML:

<!-- app/config/services.xml -->

<service id="app.user_to_username_transformer" class="AppBundle\Form\DataTransformer\UserToUsernameTransformer">
    <argument type="service" id="doctrine" />
</service>

<service id="fos_user.user_to_username_transformer" alias="app.user_to_username_transformer" />

I tried this :

app.user_to_username_transformer:
    class: 'App\Form\DataTransformer\UserToUsernameTransformer'
    arguments:
      type: "service"
      id: "doctrine"

  fos_user.user_to_username_transformer:
    alias: "app.user_to_username_transformer"

But I don't know if it's good

Upvotes: 2

Views: 2090

Answers (1)

Brucie Alpha
Brucie Alpha

Reputation: 1216

in yaml a service type="service" is prefixed with @. So your xml definition translates to

app.user_to_username_transformer:
  class: App\Form\DataTransformer\UserToUsernameTransformer
  arguments:
    - '@doctrine'

fos_user.user_to_username_transformer:
  alias: "@app.user_to_username_transformer"

More details in the docs But if you have autowire configured and your argument is typehinted properly with Doctrine\Bundle\DoctrineBundle\Registry all you need is to alias your transformer

fos_user.user_to_username_transformer:
  alias: "@App\Form\DataTransformer\UserToUsernameTransformer"

Upvotes: 2

Related Questions