<?php
namespace Freyo\LaravelQueueCMQ\Queue\Driver;
class Account
{
private $secretId;
private $secretKey;
private $cmq_client;
public function __construct($host, $secretId, $secretKey)
{
$this->host = $host;
$this->secretId = $secretId;
$this->secretKey = $secretKey;
$this->cmq_client = new CMQClient($host, $secretId, $secretKey);
}
public function set_sign_method($sign_method = 'sha1')
{
$this->cmq_client->set_sign_method($sign_method);
}
public function set_client($host, $secretId = NULL, $secretKey = NULL)
{
if ($secretId == NULL) {
$secretId = $this->secretId;
}
if ($secretKey == NULL) {
$secretKey = $this->secretKey;
}
$this->cmq_client = new CMQClient($host, $secretId, $secretKey);
}
public function get_client()
{
return $this->cmq_client;
}
public function get_queue($queue_name)
{
return new Queue($queue_name, $this->cmq_client);
}
public function list_queue($searchWord = "", $limit = -1, $offset = "")
{
$params = array();
if ($searchWord != "") {
$params['searchWord'] = $searchWord;
}
if ($limit != -1) {
$params['limit'] = $limit;
}
if ($offset != "") {
$params['offset'] = $offset;
}
$ret_pkg = $this->cmq_client->list_queue($params);
if ($offset == "") {
$next_offset = count($ret_pkg['queueList']);
} else {
$next_offset = (int)$offset + count($ret_pkg['queueList']);
}
if ($next_offset >= $ret_pkg['totalCount']) {
$next_offset = "";
}
return array("totalCount" => $ret_pkg['totalCount'],
"queueList" => $ret_pkg['queueList'], "next_offset" => $next_offset);
}
public function list_topic($searchWord = "", $limit = -1, $offset = "")
{
$params = array();
if ($searchWord != "") {
$params['searchWord'] = $searchWord;
}
if ($limit != -1) {
$params['limit'] = $limit;
}
if ($offset != "") {
$params['offset'] = $offset;
}
$resp = $this->cmq_client->list_topic($params);
if ($offset == "") {
$next_offset = count($resp['topicList']);
} else {
$next_offset = (int)$offset + count($resp['topicList']);
}
if ($next_offset >= $resp['totalCount']) {
$next_offset = "";
}
return array("totalCoult" => $resp['totalCount'],
"topicList" => $resp['topicList'],
"next_offset" => $next_offset);
}
public function get_topic($topic_name)
{
return new Topic($topic_name, $this->cmq_client);
}
public function get_subscription($topic_name, $subscription_name)
{
return new Subscription($topic_name, $subscription_name, $this->cmq_client);
}
}