Skip to content
Advertisement

Symfony4 use external class library as a service

I have a little external library that expose many classes.

Into my symfony4 project I would like to declare my class from vendor, as a service with autowire and public. So I have include my library with composer and add psr configuration like this into composer.json:

JavaScript

After that I have tried to change my services.yaml into symfony like this:

JavaScript

If I launch tests or run the application returns me this error:

JavaScript

If I declare into services.yaml the interface this works fine:

JavaScript

But I have many classes and I don’t want to declare each class, how can I fix services.yaml without declare every single service?

Thanks

Advertisement

Answer

You need to create services by hand: I did not test it but it should look like this

services.yaml

JavaScript

php

JavaScript

To be more precise you should have something like

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