mxmbsocket/lib/Ratchet/Resource/Command/Action/CloseConnection.php
Chris Boden 5386b4c066 Folder restructure
Just reorganized the folders.  Namespacing broken, unit tests broken, nothing works.
2011-11-12 14:29:10 -05:00

32 lines
970 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) {
// All this code allows an application to have its onClose method executed before the socket is actually closed
$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();
}
}