web-socket icon indicating copy to clipboard operation
web-socket copied to clipboard

How to inject dependency in BaseSocketListener subclass?

Open gianlucapisati opened this issue 7 years ago • 2 comments

if I inject the dependency that I need inside the constructor it doesn't work

/**
     * MyClass constructor.
     */
    public function __construct(MessageService $messageService)
    {
        $this->clients = new \SplObjectStorage();
        $this->messageService = $messageService;
    }

gianlucapisati avatar Apr 18 '18 16:04 gianlucapisati

This can only be done explicitly:

 App::getInstance()->make...

tabuna avatar Apr 18 '18 16:04 tabuna

You can actually do this pretty easily in the router by doing this

/** @var $this \Orchid\Socket\Console\Server */
/** @var $socket \Ratchet\App */
$articleIterationSocket = $this->getLaravel()->make('\App\Http\Sockets\ArticleIterations');
$socket->route('/', $articleIterationSocket, ['*']);

bryce13950 avatar Jul 08 '18 23:07 bryce13950