mxmbsocket/lib/Ratchet/Resource/Command/Action/SendMessage.php
Chris Boden 1b01582ab9 SocketInterface
Added unix socket methods to interface, replaced __call/call_user_func calls with concrete methods
2011-11-20 20:38:20 -05:00

43 lines
1.0 KiB
PHP

<?php
namespace Ratchet\Resource\Command\Action;
use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\Application\ApplicationInterface;
/**
* Send text back to the client end of the socket(s)
*/
class SendMessage extends ActionTemplate {
/**
* @var string
*/
protected $_message = '';
/**
* The message to send to the socket(s)
* @param string
* @return SendMessage Fluid interface
*/
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(ApplicationInterface $scope = null) {
if (empty($this->_message)) {
throw new \UnexpectedValueException("Message is empty");
}
$this->getConnection()->getSocket()->deliver($this->_message);
}
}