-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathauth.php
93 lines (79 loc) · 1.82 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
<?php namespace Laravel; use Closure;
class Auth {
/**
* The currently active authentication drivers.
*
* @var array
*/
public static $drivers = array();
/**
* The third-party driver registrar.
*
* @var array
*/
public static $registrar = array();
/**
* Get an authentication driver instance.
*
* @param string $driver
* @return Driver
*/
public static function driver($driver = null)
{
if (is_null($driver)) $driver = Config::get('auth.driver');
if ( ! isset(static::$drivers[$driver]))
{
static::$drivers[$driver] = static::factory($driver);
}
return static::$drivers[$driver];
}
/**
* Create a new authentication driver instance.
*
* @param string $driver
* @return Driver
*/
protected static function factory($driver)
{
if (isset(static::$registrar[$driver]))
{
$resolver = static::$registrar[$driver];
return $resolver();
}
switch ($driver)
{
case 'fluent':
return new Auth\Drivers\Fluent(Config::get('auth.table'));
case 'eloquent':
return new Auth\Drivers\Eloquent(Config::get('auth.model'));
default:
throw new \Exception("Auth driver {$driver} is not supported.");
}
}
/**
* Register a third-party authentication driver.
*
* @param string $driver
* @param Closure $resolver
* @return void
*/
public static function extend($driver, Closure $resolver)
{
static::$registrar[$driver] = $resolver;
}
/**
* Magic Method for calling the methods on the default cache driver.
*
* <code>
* // Call the "user" method on the default auth driver
* $user = Auth::user();
*
* // Call the "check" method on the default auth driver
* Auth::check();
* </code>
*/
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(static::driver(), $method), $parameters);
}
}