Authored by hf

do add library modles to call yohobuy api

Showing 28 changed files with 133 additions and 134 deletions
1 -<?php  
2 -/**  
3 - * User: haisheng.shen@yoho.cn  
4 - * Date: 15-2-9 下午2:08  
5 - */  
6 -  
7 -namespace LibModels;  
8 -  
9 -  
10 -class Concurrent  
11 -{  
12 -  
13 -  
14 - /**  
15 - * 添加并行的请求  
16 - * @param $url  
17 - * @param $method  
18 - * @param callable $callback  
19 - * @param null $errorCallback  
20 - */  
21 - public static function call($url, $method, array $parameters = array(), callable $callback = null, callable $errorCallback=null)  
22 - {  
23 - \Yar_Concurrent_Client::call($url, $method, $parameters, $callback, $errorCallback);  
24 - }  
25 -  
26 -  
27 - /**  
28 - * 发起请求  
29 - * @param null $callback  
30 - * @param null $errorCallback  
31 - */  
32 - public static function loop(callable $callback=null, callable $errorCallback=null)  
33 - {  
34 - \Yar_Concurrent_Client::loop($callback, $errorCallback);  
35 - }  
36 -  
37 -  
38 - /**  
39 - * 非并行yar实例的数组  
40 - * @var array  
41 - */  
42 - protected static $yarInstance = array();  
43 -  
44 - /**  
45 - * 非并行yar的实例  
46 - * @param $url  
47 - * @return mixed  
48 - */  
49 - public static function single($url, $method, array $parameters =array(), callable $callback=null, callable $errorCallback = null)  
50 - {  
51 - $key = md5($url);  
52 - if (!isset(self::$yarInstance[$key])) {  
53 - self::$yarInstance[$key] = new \Yar_Client($url);  
54 - }  
55 - try {  
56 - $result = call_user_func_array(array(self::$yarInstance[$key], $method), $parameters);  
57 - $callback($result);  
58 - } catch (\Yar_Server_Exception $e) {  
59 - if (!empty($errorCallback)) {  
60 - $errorCallback($e);  
61 - }  
62 - }  
63 - }  
64 -  
65 -  
66 - /**  
67 - * 根据参数来选择并行或者非并行  
68 - * @param $url  
69 - * @param $method  
70 - * @param array $params  
71 - * @param callable $callback  
72 - * @param callable $errorCallback  
73 - * @param bool $concurrent  
74 - */  
75 - public static function choise($url, $method, array $params=array(), callable $callback=null, callable $errorCallback = null, $concurrent=true)  
76 - {  
77 - if ($concurrent) {  
78 - self::call($url, $method, $params, $callback, $errorCallback);  
79 - } else {  
80 - self::single($url, $method, $params, $callback, $errorCallback);  
81 - }  
82 - }  
83 -}  
1 -<?php  
2 -  
3 -/**  
4 - * Created by PhpStorm.  
5 - * User: Zip  
6 - * Date: 14/11/27  
7 - * Time: 下午1:10  
8 - */  
9 -namespace LibModels;  
10 -  
11 -use Hood\Concurrent as hoodConcurrent;  
12 -  
13 -class ModelsConcurrent  
14 -{  
15 - static protected $uri = 'http://service.example.yohobuy.com/service/product/v1';  
16 -  
17 - /**  
18 - * @var Concurrent|Concurrent\Yar\Concurrent  
19 - */  
20 - static private $concurrent;  
21 -  
22 -  
23 - /**  
24 - * @return Concurrent|Concurrent\Yar\Concurrent  
25 - */  
26 - static protected function connect()  
27 - {  
28 - if (empty(self::$concurrent)) {  
29 - self::$concurrent = hoodConcurrent::yarConcurrent(self::$uri);  
30 - }  
31 - return self::$concurrent;  
32 - }  
33 -  
34 - static public function loop()  
35 - {  
36 - self::connect()->loop('Models\ModelsConcurrent::callback', 'Models\ModelsConcurrent::errorCallback');  
37 - }  
38 -  
39 - static public function errorCallback($type, $error, $callinfo)  
40 - {  
41 - print_r($error);  
42 - }  
43 -  
44 - static public function callback($ret, $callinfo)  
45 - {  
46 -  
47 - }  
48 -}  
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +use Action\AbstractAction;
  3 +/**
  4 + * 明星品牌和原创品牌
  5 + */
  6 +class PlusstarController extends AbstractAction
  7 +{
  8 +
  9 + /**
  10 + * 品牌列表页
  11 + */
  12 + public function listAction()
  13 + {
  14 + $this->_view->assign('title', 'YOHO!有货');
  15 + $this->_view->display('list', array('test' => 'hello world'));
  16 + }
  17 +
  18 + /**
  19 + * 品牌介绍页
  20 + */
  21 + public function detailAction()
  22 + {
  23 +
  24 + }
  25 +
  26 +}
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
  1 +<?php
  2 +
  3 +/*
  4 + * To change this license header, choose License Headers in Project Properties.
  5 + * To change this template file, choose Tools | Templates
  6 + * and open the template in the editor.
  7 + */
  8 +
@@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index" @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
19 application.dispatcher.defaultAction = "index" 19 application.dispatcher.defaultAction = "index"
20 20
21 ;;初始化命名空间 21 ;;初始化命名空间
22 -application.namespaces = "Action,Api,Plugin" 22 +application.namespaces = "Action,Api,LibModels,Plugin"
23 23
24 ;;使用composer 24 ;;使用composer
25 composer.autoload = 0 25 composer.autoload = 0
@@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index" @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
19 application.dispatcher.defaultAction = "index" 19 application.dispatcher.defaultAction = "index"
20 20
21 ;;初始化命名空间 21 ;;初始化命名空间
22 -application.namespaces = "Action,Api,Plugin" 22 +application.namespaces = "Action,Api,LibModels,Plugin"
23 23
24 ;;使用composer 24 ;;使用composer
25 composer.autoload = 0 25 composer.autoload = 0
@@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index" @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
19 application.dispatcher.defaultAction = "index" 19 application.dispatcher.defaultAction = "index"
20 20
21 ;;初始化命名空间 21 ;;初始化命名空间
22 -application.namespaces = "Action,Api,Plugin" 22 +application.namespaces = "Action,Api,LibModels,Plugin"
23 23
24 ;;使用composer 24 ;;使用composer
25 composer.autoload = 0 25 composer.autoload = 0