Factory.php
2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
namespace Plugin\Partner;
isset($_SESSION) || session_start();
defined('DS') || define('DS', '/');
/**
* 抽象类: 第三方接口都会继承该类
*
* @name Factory
* @package library/Plugin/Partner
* @copyright yoho.inc
* @version 1.0 (2015-10-10 17:11:10)
* @author fei.hong <fei.hong@yoho.cn>
*/
abstract class Factory
{
/**
* 接口名称
*
* @var string
*/
protected $apiName = '';
/**
* 接口配置
*
* @var array
*/
protected $apiConfig = array();
/**
* 接口对象
*
* @var array
*/
protected static $apiObjs = array();
/**
* 单例模式: 实例化需要调用的接口对象
*
* @param string $apiName 接口名称
* @return object
*/
public static function create($apiName)
{
$apiName = strtolower($apiName);
if (!isset(self::$apiObjs[$apiName]))
{
// require dirname(__FILE__) . DS . $apiName . DS . 'Call.class.php';
//$apiNameCase = ucfirst($apiName);
$apiClass = "Plugin\Partner\\{$apiName}\Call";
self::$apiObjs[$apiName] = new $apiClass();
self::$apiObjs[$apiName]->apiName = $apiName;
self::$apiObjs[$apiName]->configure();
self::$apiObjs[$apiName]->init();
}
return self::$apiObjs[$apiName];
}
/**
* 应用的配置
*
* @return void
*/
protected function configure()
{
$this->apiConfig = require(dirname(__FILE__) . DS . $this->apiName . DS . 'Config.inc.php');
}
/**初始化*/
abstract protected function init();
/**获取接口*/
abstract public function getAuthorizeUrl();
abstract public function getAccessToken();
abstract public function getUserInfo($token);
abstract public function getFriends($token, $params);
/**同步分享*/
abstract public function syncShare($token, $content, $image, $link);
}