Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The service ".service_locator.VS38E50" has a dependency on a non-existent service "Gos\Bundle\WebSocketBundle\Pusher\Wamp\WampPusher". #456

Open
ViktorieTrungerova opened this issue Nov 4, 2021 · 5 comments
Labels

Comments

@ViktorieTrungerova
Copy link

services.yml

gos_web_socket:
    server:
        port: 8888        # The port the socket server will listen on
        host: 127.0.0.1   # The host ip to bind to
        router:
            resources:
                - '%kernel.project_dir%/config/pubsub/routing.yaml'
    client:
        firewall: [api, login, dev, main] # Can be an array of firewalls
        session_handler: 'session.handler.pdo'
    pushers:
        wamp:
            enabled: true # Flag to enable this pusher
            host: 127.0.0.1 # This will probably be the same as your `gos_web_socket.server.host` value
            port: 80 # This will probably be the same as your `gos_web_socket.server.port` value
            ssl: false # Flag to enable SSL connections to the websocket server, default false
            origin: null # The origin domain for the pusher, default null (if origin checking is enabled on your websocket server, this value must be allowed)

MyController.php

<?php

namespace App\Controller;

use App\Repository\LanguageRepository;
use App\Repository\ProfileRepository;
use App\Repository\Repository;
use App\Websocket\WsNotificator;
use Gos\Bundle\WebSocketBundle\Pusher\PusherInterface;
use Gos\Bundle\WebSocketBundle\Pusher\Wamp\WampPusher;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Cache\CacheInterface;

/**
 * @Route("/api/language", name="language_api")
 */
class LanguageController extends BaseEntityController {

	/**
	 * @Route("/", name="default", methods={"GET"})
	 */
	public function defaultAction(Request $request): ?JsonResponse
	{

		/** @var PusherInterface $pusher */
		$pusher = $this->get('gos_web_socket.pusher.wamp');
		$pusher->push(['msg' => 'hello'], 'chat.topic');
		var_dump('ok');
		die;
	}

	public static function getSubscribedServices()
	{
		return array_merge(
			parent::getSubscribedServices(),
			[
				'gos_web_socket.pusher.wamp' => WampPusher::class,
			]
		);
	}

}

When I have method getSubscribedServices in my controller and clear cache I get following error:

The service ".service_locator.VS38E50" has a dependency on a non-existent service "Gos\Bundle\WebSocketBundle\Pusher\Wamp\WampPusher".

Missing something in my config?

@mbabker
Copy link
Contributor

mbabker commented Nov 4, 2021

Truthfully, I've never messed with the getSubscribedServices method, so I'm not entirely sure that the pushers will work with it (looking at what's in the abstract controller, all of those services are referenced by a class or interface name, and the pushers aren't registered in the container with those types of IDs).

You might be better off injecting the pusher as an argument to your controller instead of using the getSubscribedServices method. At least, https://symfony.com/doc/current/service_container/service_subscribers_locators.html doesn't give me much confidence that you can use it without having class-based service IDs.

@ViktorieTrungerova
Copy link
Author

thanks for answer, but when I try inject pusher as argument to my controller in costructor

/**
 * @Route("/api/language", name="language_api")
 */
class LanguageController extends BaseEntityController {

	private WsNotificator $wsNotificator;
	private PusherInterface $pusher;

	public function __construct(
		LoggerInterface $logger,
		LanguageRepository $repository,
		ProfileRepository $profileRepository,
		WsNotificator $wsNotificator,
		CacheInterface $cacheApp,
		PusherInterface $pusher
	){
		parent::__construct($logger, $repository, $profileRepository, $cacheApp);
		$this->wsNotificator = $wsNotificator;
		$this->pusher = $pusher;
	}

I get this error:

Cannot autowire service "App\Controller\LanguageController": argument "$pusher" of method "__construct()" references interface "Gos\Bundle\WebSocketBundle\Pusher\PusherInterface" but no such service exists. Did you create a class that implements this interface?

And When I try get service by name

	/**
	 * @Route("/", name="add", methods={"GET"})
	 */
	public function defaultAction(Request $request): ?JsonResponse
	{

		/** @var PusherInterface $pusher */
		$pusher = $this->get('gos_web_socket.pusher.wamp');
		$pusher->push(['msg' => 'hi'], 'chat.topic');
		die;
	}

I get error:

Service "gos_web_socket.pusher.wamp" not found: even though it exists in the app's container, the container inside "App\Controller\LanguageController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "message_bus", "messenger.default_bus", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.

but when I try bin/console debug:container gos_web_socket.pusher, service exist

 ---------------- ----------------------------------------------------------------- 
  Option           Value                                                            
 ---------------- ----------------------------------------------------------------- 
  Service ID       gos_web_socket.pusher.wamp.data_collector                        
  Class            Gos\Bundle\WebSocketBundle\Pusher\DataCollectingPusherDecorator  
  Tags             gos_web_socket.pusher (alias: wamp)                              
  Public           no                                                               
  Synthetic        no                                                               
  Lazy             no                                                               
  Shared           yes                                                              
  Abstract         no                                                               
  Autowired        no                                                               
  Autoconfigured   no                                                               
 ---------------- ----------------------------------------------------------------- 

Some idea? Thanks very much

@mbabker
Copy link
Contributor

mbabker commented Nov 4, 2021

You can't use autowiring to inject pushers, they all share a common interface (and are decorated in debug mode) so nothing can reliably set an alias to Gos\Bundle\WebSocketBundle\Pusher\PusherInterface in the service container. You're going to have to manually define that argument for your service configurations wherever you need it injected.

@ViktorieTrungerova
Copy link
Author

I am sorry, I am newbie in symfony and I am not sure how do you think exactly.

I have registered only one pusher (wamp)

gos_web_socket:
   pushers:
      wamp: enabled: true
      host: 127.0.0.1
      port: 80
      ssl: false
      origin: null

You say that I have to manually define argument in my config like this?

App\Controller\LanguageController:
class: App\Controller\LanguageController:
arguments:
    $pusher: '@gos_web_socket.pusher.wamp'

My controller

class LanguageController extends BaseEntityController {

	private WsNotificator $wsNotificator;
	private WampPusher $pusher;

	public function __construct(
		WampPusher $pusher,
		LoggerInterface $logger,
		LanguageRepository $repository,
		ProfileRepository $profileRepository,
		WsNotificator $wsNotificator,
		CacheInterface $cacheApp
	){
		parent::__construct($logger, $repository, $profileRepository, $cacheApp);
		$this->wsNotificator = $wsNotificator;
		$this->pusher = $pusher;
	}

but I get error:

Cannot autowire service "App\Controller\LanguageController": argument "$pusher" of method "__construct()" references class "Gos\Bundle\WebSocketBundle\Pusher\Wamp\WampPusher" but no such service exists.

@MeK-KeM
Copy link

MeK-KeM commented Feb 9, 2024

Same issue on prestashop v8.0.0 built on symfony

The service "PrestaShopBundle\Security\OAuth2\Repository\ClientRepository" has a dependency on a non-existent service "security.user.provider.concrete.oauth2".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants