Authored by whb

修改配置

... ... @@ -13,8 +13,7 @@
],
"autoload": {
"psr-4": {
"QSns\\": "src/QSns",
"QSnsApi\\":"src/QSnsApi"
"QSns\\": "src/QSns"
}
},
"require": {
... ...
<?php
use Action\RootAction;
class IndexController extends RootAction
{
public function indexAction()
{
$this->_viewScriptPush(
array('bootstrap', 'cookies', 'custom', 'jquery.dataTables', 'dataTables.responsive', 'dataTables.bootstrap')
);
$this->_viewLink()->offsetSetFile(103, $this->_css('dataTables', true));
$this->_assign('tab',array($this->getRequest()->getModuleName(),$this->getRequest()->getControllerName(),$this->getRequest()->getActionName()));
}
public function addAction()
{
$this->_viewLink()
->offsetSetFile(20, $this->_css('jquery.tagsinput', true))
->offsetSetFile(21, $this->_css('toggles', true));
$this->_viewScriptPush(array(
'bootstrap', 'cookies', 'custom','retina', 'pace', 'modernizr', 'jquery-migrate',
'jquery-ui', 'autogrow-textarea',
'jquery.mousewheel', 'jquery.tagsinput', 'toggles',
'select2'
));
$this->_assign('tab',array($this->getRequest()->getModuleName(),$this->getRequest()->getControllerName(),$this->getRequest()->getActionName()));
}
}
\ No newline at end of file
... ...
;profile
product.index.type = "rewrite"
product.index.match = "/product/$"
product.index.route.module = Product
product.index.route.controller = Index
product.index.route.action = Index
\ 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