mxmbsocket/lib/Ratchet/Resource/Command/Action/CloseConnection.php
Chris Boden f3c7dd4d7f Socket Proxy
Replaced passing SocketInterface everywhere with a proxy object
2011-11-14 15:56:30 -05:00

32 lines
1.0 KiB
PHP

<?php
namespace Ratchet\Resource\Command\Action;
use Ratchet\Resource\Command\ActionTemplate;
use Ratchet\Application\ApplicationInterface;
use Ratchet\Resource\Connection;
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(ApplicationInterface $scope = null) {
// All this code allows an application to have its onClose method executed before the socket is actually closed
$ret = $scope->onClose($this->getConnection());
if ($ret instanceof CommandInterface) {
$comp = new Composite;
$comp->enqueue($ret);
$rt = new Runtime($this->getConnection());
$rt->setCommand(function(Connection $conn, ApplicationInterface $scope) {
$conn->getSocket()->close();
});
$comp->enqueue($rt);
return $comp;
}
$this->getConnection()->getSocket()->close();
}
}