0
votes

I want to change my services to use the autowire function of symfony 3. I make it work for most of them, but I still have probem with services using some params.

For services using others services I just delete them from my services file after the autowire config. But I still have services like this

App\MyBundle\Lib\GraphLib: ["@serv.carslib","@serv.buslib","%kernel.root_dir%","@translator","%version%"]

My constructor look like this

public function __construct(CarsLib $carsLib, BusLib $busLib, $rootdir, TranslatorInterface $translator, $version){

Is there a way to autowire this service with parameters? If not how can I change the parameter @serv.carslib and @serv.buslib. Because this services are autowired and can't made somthing like this worked

App\MyBundle\Lib\GraphLib: ["@App\MyBundle\Lib\CarLib","@App\MyBundle\Lib\BusLib","%kernel.root_dir%","@translator","%version%"]

Edit 1 : I try to change my service like this but I have an error 'The service has a dependency on a non-existent service'

App\MyBundle\Lib\GraphLib: 
    arguments:
        $carsLib: "@App\MyBundle\Lib\CarLib"
        $busLib: "@App\MyBundle\Lib\BusLib"
        $rootdir: "%kernel.root_dir%"
        $translator: "@translator"
        $version: "%version%"

I also try somthing like this

App\MyBundle\Lib\GraphLib: 
    arguments:
        $rootdir: "%kernel.root_dir%"
        $version: "%version%"

I changed the params order in my controller like this

public function __construct(CarsLib $carsLib, BusLib $busLib, TranslatorInterface $translator, $rootdir, $version){

But I have this error : Invalid constructor argument 4 for service argument 1 must be defined before

2
Paste you whole services.yml. It will be easier to help. - Wolen

2 Answers

0
votes

You can set manually arguments for your service. Rest of arguments should be autowired . Your services.yml should look like this

services:
  #...

  App\Some\Service:
    arguments:
      $arg1: 'arg1'

Here you can read more about manually wiring arguments.

0
votes

I change my service like this with single quote and it works

App\MyBundle\Lib\GraphLib: 
arguments:
    $carsLib: '@App\MyBundle\Lib\CarLib'
    $busLib: '@App\MyBundle\Lib\BusLib'
    $rootdir: '%kernel.root_dir%'
    $translator: '@translator'
    $version: '%version%'