mxmbsocket/lib/Ratchet/Command/SendMessage.php
Chris Boden 3127efc981 Cleanup
Removed redundant Interfaces
Removed a number of unused methods
2011-11-01 09:52:41 -04:00

52 lines
1.1 KiB
PHP

<?php
namespace Ratchet\Command;
use Ratchet\SocketCollection;
/**
* Send text back to the client end of the socket(s)
*/
class SendMessage implements CommandInterface {
/**
* @var SocketCollection
*/
protected $_sockets;
/**
* @var string
*/
protected $_message = '';
public function __construct(SocketCollection $sockets) {
$this->_sockets = $sockets;
}
/**
* The message to send to the socket(s)
* @param string
*/
public function setMessage($msg) {
$this->_message = (string)$msg;
return $this;
}
/**
* Get the message from setMessage()
* @return string
*/
public function getMessage() {
return $this->_message;
}
/**
* @throws \UnexpectedValueException if a message was not set with setMessage()
*/
public function execute() {
if (empty($this->_message)) {
throw new \UnexpectedValueException("Message is empty");
}
foreach ($this->_sockets as $current) {
$current->write($this->_message, strlen($this->_message));
}
}
}