web-socket
web-socket copied to clipboard
How to inject dependency in BaseSocketListener subclass?
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;
}
This can only be done explicitly:
App::getInstance()->make...
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, ['*']);