Skip to content
Advertisement

Symfony inject array through services.yaml

I am trying to inject an array to Event Subscriber, but I also inject an other repository so I don’t know how this will work:

Here’s what I am trying:

services.yaml

JavaScript

TerminateSubscriber.php:

JavaScript

It says that the first parameter should be an instance of the Repo, array given. But if I switch the parameters it says “optional parameter given before required”

EDIT

The array should look like this:

JavaScript

Advertisement

Answer

You are very close but you need some changes in your code. If you need to pass a Repository, array or string from service to class you need to pass it like this.

In service.yaml :

JavaScript

And in your construct:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement