mxmbsocket/lib/Ratchet/Command/Action/CloseConnection.php
Chris Boden 15ec375405 Closure
onClose hook is triggered upon is CloseConnection command (server side) now.  Allowing applications to handle any final executions before the connection is closed.
Updated some API documentation.
2011-11-08 11:04:30 -05:00

32 lines
851 B
PHP

<?php
namespace Ratchet\Command\Action;
use Ratchet\Command\ActionTemplate;
use Ratchet\SocketObserver;
use Ratchet\SocketInterface;
use Ratchet\Command\CommandInterface;
use Ratchet\Command\Composite;
/**
* Close the connection to the sockets passed in the constructor
*/
class CloseConnection extends ActionTemplate {
function execute(SocketObserver $scope = null) {
$ret = $scope->onClose($this->getSocket());
if ($ret instanceof CommandInterface) {
$comp = new Composite;
$comp->enqueue($ret);
$rt = new Runtime($this->getSocket());
$rt->setCommand(function(SocketInterface $socket, SocketObserver $scope) {
$socket->close();
});
$comp->enqueue($rt);
return $comp;
}
$this->getSocket()->close();
}
}