Factory.class.php
1.89 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
<?php
isset($_SESSION) || session_start();
defined('DS') || define('DS', '/');
/**
* 抽象类: 第三方接口都会继承该类
*
* @name Lib_Api_Partner
* @package lib/api
* @copyright yoho.inc
* @version 4.0 (2013-12-19 13:41:10)
* @author fei.hong <fei.hong@yoho.cn>
*/
abstract class Lib_Partner_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 = "Lib_Partner_{$apiNameCase}_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);
}