03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Real Time Chat 183<br />

16 return $this->socket;<br />

17 }<br />

18<br />

19 public function setSocket(ConnectionInterface $socket)<br />

20 {<br />

21 $this->socket = $socket;<br />

22 return $this;<br />

23 }<br />

24<br />

25 public function getId()<br />

26 {<br />

27 return $this->id;<br />

28 }<br />

29<br />

30 public function setId($id)<br />

31 {<br />

32 $this->id = $id;<br />

33 return $this;<br />

34 }<br />

35<br />

36 public function getName()<br />

37 {<br />

38 return $this->name;<br />

39 }<br />

40<br />

41 public function setName($name)<br />

42 {<br />

43 $this->name = $name;<br />

44 return $this;<br />

45 }<br />

46 }<br />

.<br />

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

The User class is a simple wrapper for a socket resource and name string. The way we’ve<br />

chosen to implement the Ratchet server requires that we have a class which implements the<br />

MessageComponentInterface interface; and this interface specifies that ConnectionInterface<br />

objects are passed back and forth. There’s no way to identify these, by name (and id), so we’re<br />

adding that functionality with the extra layer.

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

Saved successfully!

Ooh no, something went wrong!