forked from ranlt/FuelPHP-Auth-AJAX
/
driver.php
119 lines (101 loc) · 2.17 KB
/
driver.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Fuel
*
* Fuel is a fast, lightweight, community driven PHP5 framework.
*
* @package Fuel
* @version 1.0
* @author Fuel Development Team
* @license MIT License
* @copyright 2010 - 2011 Fuel Development Team
* @link http://fuelphp.com
*/
namespace Auth;
abstract class Auth_Driver {
/**
* @var Auth_Driver
* THIS MUST BE DEFINED IN THE BASE EXTENSION
*/
// protected static $_instance = null;
/**
* @var array contains references if multiple were loaded
* THIS MUST BE DEFINED IN THE BASE EXTENSION
*/
// protected static $_instances = array();
public static function factory(Array $config = array())
{
throw new \Auth_Exception('Driver must have a factory method extension.');
}
/**
* Return a specific driver, or the default instance
*
* @param string driver id
* @return Auth_Driver
*/
public static function instance($instance = null)
{
if ($instance === true)
{
return static::$_instances;
}
elseif ($instance !== null)
{
if ( ! array_key_exists($instance, static::$_instances))
{
return false;
}
return static::$_instances[$instance];
}
if (static::$_instance === null)
{
static::$_instance = static::factory();
}
return static::$_instance;
}
// ------------------------------------------------------------------------
/**
* @var string instance identifier
*/
protected $id;
/**
* @var array given configuration array
*/
protected $config = array();
protected function __construct(Array $config)
{
$this->id = $config['id'];
$this->config = array_merge($this->config, $config);
}
/**
* Get driver instance ID
*
* @return string
*/
public function get_id()
{
return (string) $this->id;
}
/**
* Create or change config value
*
* @param string
* @param mixed
*/
public function set_config($key, $value)
{
$this->config[$key] = $value;
}
/**
* Retrieve config value
*
* @param string
* @param mixed return when key doesn't exist
* @return mixed
*/
public function get_config($key, $default = null)
{
return array_key_exists($key, $this->config) ? $this->config[$key] : $default;
}
}
/* end of file driver.php */