03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Real Time Chat 177<br />

29 {<br />

30 return new User();<br />

31 });<br />

32<br />

33 $this->app->bind("chat.command.serve", function()<br />

34 {<br />

35 return new Command\Serve(<br />

36 $this->app->make("chat.chat")<br />

37 );<br />

38 });<br />

39<br />

40 $this->commands("chat.command.serve");<br />

41 }<br />

42<br />

43 public function provides()<br />

44 {<br />

45 return [<br />

46 "chat.chat",<br />

47 "chat.command.serve",<br />

48 "chat.emitter",<br />

49 "chat.server"<br />

50 ];<br />

51 }<br />

52 }<br />

This file should be saved as workbench/formativ/chat/src/Formativ/Chat/ChatServiceProvider.php.<br />

.<br />

The first binding is a simple alias to the EvenementEventEmitter class (which Ratchet requires).<br />

We bind it here as we cannot guarantee that Ratchet will continue to use EvenementEventEmitter<br />

and we’ll need a reliable way to unit test possible alternatives in the future.<br />

Creating A Chat Handler<br />

Let’s look closer at the second and third bindings. The first is to the Chat class. It implements the<br />

ChatInterface interface:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!