Authored by hf

do add library modles to call yohobuy api

Showing 28 changed files with 133 additions and 134 deletions
<?php
/**
* User: haisheng.shen@yoho.cn
* Date: 15-2-9 下午2:08
*/
namespace LibModels;
class Concurrent
{
/**
* 添加并行的请求
* @param $url
* @param $method
* @param callable $callback
* @param null $errorCallback
*/
public static function call($url, $method, array $parameters = array(), callable $callback = null, callable $errorCallback=null)
{
\Yar_Concurrent_Client::call($url, $method, $parameters, $callback, $errorCallback);
}
/**
* 发起请求
* @param null $callback
* @param null $errorCallback
*/
public static function loop(callable $callback=null, callable $errorCallback=null)
{
\Yar_Concurrent_Client::loop($callback, $errorCallback);
}
/**
* 非并行yar实例的数组
* @var array
*/
protected static $yarInstance = array();
/**
* 非并行yar的实例
* @param $url
* @return mixed
*/
public static function single($url, $method, array $parameters =array(), callable $callback=null, callable $errorCallback = null)
{
$key = md5($url);
if (!isset(self::$yarInstance[$key])) {
self::$yarInstance[$key] = new \Yar_Client($url);
}
try {
$result = call_user_func_array(array(self::$yarInstance[$key], $method), $parameters);
$callback($result);
} catch (\Yar_Server_Exception $e) {
if (!empty($errorCallback)) {
$errorCallback($e);
}
}
}
/**
* 根据参数来选择并行或者非并行
* @param $url
* @param $method
* @param array $params
* @param callable $callback
* @param callable $errorCallback
* @param bool $concurrent
*/
public static function choise($url, $method, array $params=array(), callable $callback=null, callable $errorCallback = null, $concurrent=true)
{
if ($concurrent) {
self::call($url, $method, $params, $callback, $errorCallback);
} else {
self::single($url, $method, $params, $callback, $errorCallback);
}
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 14/11/27
* Time: 下午1:10
*/
namespace LibModels;
use Hood\Concurrent as hoodConcurrent;
class ModelsConcurrent
{
static protected $uri = 'http://service.example.yohobuy.com/service/product/v1';
/**
* @var Concurrent|Concurrent\Yar\Concurrent
*/
static private $concurrent;
/**
* @return Concurrent|Concurrent\Yar\Concurrent
*/
static protected function connect()
{
if (empty(self::$concurrent)) {
self::$concurrent = hoodConcurrent::yarConcurrent(self::$uri);
}
return self::$concurrent;
}
static public function loop()
{
self::connect()->loop('Models\ModelsConcurrent::callback', 'Models\ModelsConcurrent::errorCallback');
}
static public function errorCallback($type, $error, $callinfo)
{
print_r($error);
}
static public function callback($ret, $callinfo)
{
}
}
\ No newline at end of file
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
use Action\AbstractAction;
/**
* 明星品牌和原创品牌
*/
class PlusstarController extends AbstractAction
{
/**
* 品牌列表页
*/
public function listAction()
{
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('list', array('test' => 'hello world'));
}
/**
* 品牌介绍页
*/
public function detailAction()
{
}
}
\ No newline at end of file
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
... ... @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Api,Plugin"
application.namespaces = "Action,Api,LibModels,Plugin"
;;使用composer
composer.autoload = 0
... ...
... ... @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Api,Plugin"
application.namespaces = "Action,Api,LibModels,Plugin"
;;使用composer
composer.autoload = 0
... ...
... ... @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Api,Plugin"
application.namespaces = "Action,Api,LibModels,Plugin"
;;使用composer
composer.autoload = 0
... ...