whale 169a751e0f update to 1.2 version
Generate systemd script
Default info_level set to 2
Modify & add some comment for Example module
Brand new Console
Add daemon command argument
Add #OnTick annotation
Add ZMRobot API class
2020-04-29 15:29:56 +08:00

83 lines
1.7 KiB
PHP

<?php
namespace ZM\Context;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
use swoole_server;
use ZM\Connection\ConnectionManager;
use ZM\Connection\CQConnection;
use ZM\Http\Response;
use ZM\Utils\ZMRobot;
class Context implements ContextInterface
{
private $server = null;
private $frame = null;
private $data = null;
private $request = null;
private $response = null;
private $cid;
public function __construct($param, $cid) {
if (isset($param["server"])) $this->server = $param["server"];
if (isset($param["frame"])) $this->frame = $param["frame"];
if (isset($param["data"])) $this->data = $param["data"];
if (isset($param["request"])) $this->request = $param["request"];
if (isset($param["response"])) $this->response = $param["response"];
$this->cid = $cid;
}
/**
* @return swoole_server|null
*/
public function getServer() {
return $this->server;
}
/**
* @return Frame|null
*/
public function getFrame() {
return $this->frame;
}
/**
* @return array|null
*/
public function getData() {
return $this->data;
}
/**
* @return Request|null
*/
public function getRequest() {
return $this->request;
}
/**
* @return Response|null
*/
public function getResponse() {
return $this->response;
}
/**
* @return int|null
*/
public function getCid() {
return $this->cid;
}
/**
* @return ZMRobot|null
*/
public function getRobot() {
$conn = ConnectionManager::get($this->getFrame()->fd);
return $conn instanceof CQConnection ? new ZMRobot($conn) : null;
}
}