1

I'm new to Symfony and try to use the ClientManipulatorInterface service from gos/web-socket-bundle. My problem is that Symfony returns an error even if I configure the argument manually.

I always get this error: Cannot autowire service "Foo\Bar\Controller\testTopic": argument "$clientManipulator" of method "__construct()" references interface "Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface" but no such service exists. You should maybe
alias this interface to the existing "gos_web_socket.websocket.client_manipulator" service.

Here is my service.yaml:

services: test_topic: class: Foo\Bar\Controller\testTopic tags: - { name: gos_web_socket.topic } arguments: - '@gos_web_socket.websocket.client_manipulator' 

This is my PHP class:

namespace Foo\Bar\Controller; use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface; use Gos\Bundle\WebSocketBundle\Topic\TopicInterface; class testTopic implements TopicInterface { /** * @var ClientManipulatorInterface */ protected $clientManipulator; /** * testTopic constructor. * @param ClientManipulatorInterface $clientManipulator */ public function __construct(ClientManipulatorInterface $clientManipulator) { $this->clientManipulator = $clientManipulator; } ... 
1
  • 2
    I know you already accepted the answer but the actual problem with your config is that you used a service id of test_topic instead of Foo\Bar\Controller\testTopic. The error message is actually coming from autowire as it scans all of your classes and attempts to automatically convert them to services. Autowire uses the class name so see if a service is manually defined. In your case, it does not find your service so it tries to create it and runs into the interface problem. In other words, change the service id to the class name and your original config would work. Commented Oct 5, 2018 at 14:24

1 Answer 1

1

You need to alias the ClientManipulatorInterface to one of it's implementations for Symfony to be able to autowire the dependency correctly:

services: Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface: '@gos_web_socket.websocket.client_manipulator' Foo\Bar\Controller\testTopic: autowire: true tags: - { name: gos_web_socket.topic } 

Clear your cache afterwards!

Sign up to request clarification or add additional context in comments.

2 Comments

I expected that it is automatically done because it is defined in the gos/web-socket-bundle. Now I defined it also in my services.yaml and it work's. Thanks.
The bundle's service-definitions don't include the interface alias - that's why auto-wiring doesn't work out of the box.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.