mxmbsocket/lib/Ratchet/Resource/Command/Action/CloseConnection.php
Chris Boden 47b7110dc1 Namespaces
Fixed all the namespaces to match new folder structure
2011-11-12 20:51:54 -05:00

32 lines
1015 B
PHP

<?php
namespace Ratchet\Resource\Command\Action;
use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\ObserverInterface;
use Ratchet\SocketInterface;
use Ratchet\Resource\Command\CommandInterface;
use Ratchet\Resource\Command\Composite;
/**
* Close the connection to the sockets passed in the constructor
*/
class CloseConnection extends ActionTemplate {
function execute(ObserverInterface $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, ObserverInterface $scope) {
$socket->close();
});
$comp->enqueue($rt);
return $comp;
}
$this->getSocket()->close();
}
}