-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auth.php
executable file
·103 lines (94 loc) · 1.81 KB
/
Auth.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
*
* -+-----------------------------------
* |PHP5 Framework - 2011
* |Web Site: www.iblue.cc
* |E-mail: [email protected]
* |Date: 2012-01-11
* -+-----------------------------------
*
* @desc 认证
* @author jingke
*/
class XF_Auth
{
/**
* 当前实例
* @var XF_Auth
*/
protected static $_instance = NULL;
/**
* 认证适配器
* @var XF_Auth_Adapter_Interface
*/
protected $_adapter = NULL;
/**
* 存储器
* @var XF_Auth_Storage_Interface
*/
protected $_storage = NULL;
protected function __clone()
{}
protected function __construct()
{}
/**
* 获取当前实例
* @return XF_Auth
*/
public static function getInstance()
{
if (self::$_instance === NULL)
self::$_instance = new self();
return self::$_instance;
}
/**
* 认证
* @return XF_Auth_Result
*/
public function authenticate()
{
if ($this->_adapter === NULL)
throw new XF_Auth_Exception('Lack of authentication adapter!');
$authResult = $this->_adapter->authenticate();
$this->getStorage();
$this->_storage->clear();
if ($authResult->isAuthOK())
{
$this->_storage->write($authResult->getIdentity());
}
return $authResult;
}
/**
* 设置认证适配器
* @param XF_Auth_Adapter_Interface $adapter
* @return XF_Auth
*/
public function setAdapter(XF_Auth_Adapter_Interface $adapter)
{
$this->_adapter = $adapter;
return $this;
}
/**
* 获取存储器
* @return XF_Auth_Storage_Interface
*/
public function getStorage()
{
if (NULL === $this->_storage)
{
$this->setStorage(new XF_Auth_Storage_Session());
}
return $this->_storage;
}
/**
* 设置存储器
* @param XF_Auth_Storage_Interface $storage
* @return XF_Auth
*/
public function setStorage(XF_Auth_Storage_Interface $storage)
{
$this->_storage = $storage;
return $this;
}
}