Authored by whb

sns service

{
"name": "QProduct",
"description": "QSns",
"keywords": ["QSns"],
"homepage": "http://git.dev.yoho.cn/web/qsns.git",
"type": "library",
"authors": [
{
"name": "zip",
"email": "54152649@qq.com",
"homepage": "http://www.sou5.cn"
}
],
"autoload": {
"psr-4": {
"QSns\\": "src/QSns"
}
},
"require": {
"php": ">=5.3.0"
},
"extra": {
"branch-alias": {
"dev-master": "master"
}
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 15/4/5
* Time: 下午5:03
*/
namespace QProduct;
class Config
{
/**
* DB前缀
*/
const DB_PREFIX = 'qin_';
/**
* 模块名称
* @var string
*/
public static $modelsName = 'QProduct';
/**
* app 模块名称
* @var array
*/
public static $appName = array(
'Product'
);
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 15/4/6
* Time: 下午3:06
*/
namespace QSns;
use Hood\DB;
class Dao
{
protected $key = '';
/**
* @var \Hood\Dao\Db\PDOMySQL\Quick
*/
private $_dao = null;
private $dbName = '';
public function __construct($dbName = 'sns')
{
$this->key = $this->dbName = Config::DB_PREFIX . $dbName;
}
/**
* @param string $database
* @return \Hood\Dao\Db\PDOMySQL\Quick
*/
protected function dao()
{
if ($this->_dao == null) {
$this->_dao = DB::Quick($this->dbName);
}
return $this->_dao;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 15/4/6
* Time: 下午10:06
*/
namespace QSnsApi;
class ApiAbstract
{
/**
* @param $serviceUri
* @return YarConcurrent
*/
protected static function concurrent($className)
{
return new YarConcurrent(Config::getUri($className));
}
/**
* @param $serviceUri
* @return \Yar_Client
*/
protected static function client($className)
{
echo Config::getUri($className);
exit();
$yarClient = new \Yar_Client(Config::getUri($className));
$yarClient->setOpt(YAR_OPT_CONNECT_TIMEOUT, 1000);
return $yarClient;
}
}
\ No newline at end of file
... ...
<?php
namespace QSnsApi;
class Config
{
public static $production = "/service/";
public static $testing = "/service/";
public static $developer = "/service/";
/**
* ClassNameUriList ,
* 可以定义不同的方法的地址,主要是本地开发使用
* 或者使用非本站点的Service
* @var array
*/
public static $productionClassNameUri = array(
'admin.profile' => 'http://www.qin.com/service/admin/profile'
);
/**
* 测试配置列表
* @var array
*/
public static $testingClassNameUri = array();
/**
* 开发者配置列表
* @var array
*/
public static $developerClassNameUri = array(
'admin.profile' => 'http://www.yoho.com/service/admin/profile',
);
/**
* 获取URI
* @param $className
* @return string
*/
public static function getUri($className)
{
$environ = ini_get('yaf.environ');
$environClassName = $environ . 'ClassNameUri';
if (!property_exists('QApi\Config', $environClassName)) {
throw new \Exception('Environ Class Is Null.');
}
$environClassList = self::$$environClassName;
if (isset($environClassList[$className])) {
return $environClassList[$className];
}
if (!isset(self::$$environ) || !isset($_SERVER['HTTP_HOST'])) {
throw new \Exception('Service Url Is Null.');
}
$className = str_replace(array('.'), array('/'), $className);
return 'http://' . $_SERVER['HTTP_HOST'] . self::$$environ . $className;
}
}
\ No newline at end of file
... ...
<?php
namespace QSnsApi;
class YarClient
{
private $uri;
public function __construct($uri)
{
$this->uri = $uri;
}
/**
* @return \Yar_Client
*/
public function call()
{
return new \Yar_Client($this->uri);
}
}
\ No newline at end of file
... ...
<?php
namespace QSnsApi;
class YarConcurrent
{
private $uri;
public function __construct($uri)
{
$this->uri = $uri;
}
public function call($method, $parameters, $callback)
{
\Yar_Concurrent_Client::call($this->uri, $method, $parameters, $callback);
return $this;
}
public function loop($callback = 'QSnsApi\YarConcurrent::callback', $error_callback = 'QSnsApi\YarConcurrent::errorCallback')
{
\Yar_Concurrent_Client::loop($callback, $error_callback);
return $this;
}
/**
* 错误回调
* @param $type
* @param $error
* @param $callinfo
*/
static public function errorCallback($type, $error, $callinfo)
{
print_r($error);
}
/**
* 发送所有注册的并行调用
* @param $retval
* @param $callinfo
*/
static public function callback($retval, $callinfo)
{
}
}
\ No newline at end of file
... ...