1: <?php namespace Laravel; use Closure;
2:
3: class Auth {
4:
5: /**
6: * The currently active authentication drivers.
7: *
8: * @var array
9: */
10: public static $drivers = array();
11:
12: /**
13: * The third-party driver registrar.
14: *
15: * @var array
16: */
17: public static $registrar = array();
18:
19: /**
20: * Get an authentication driver instance.
21: *
22: * @param string $driver
23: * @return Driver
24: */
25: public static function driver($driver = null)
26: {
27: if (is_null($driver)) $driver = Config::get('auth.driver');
28:
29: if ( ! isset(static::$drivers[$driver]))
30: {
31: static::$drivers[$driver] = static::factory($driver);
32: }
33:
34: return static::$drivers[$driver];
35: }
36:
37: /**
38: * Create a new authentication driver instance.
39: *
40: * @param string $driver
41: * @return Driver
42: */
43: protected static function factory($driver)
44: {
45: if (isset(static::$registrar[$driver]))
46: {
47: $resolver = static::$registrar[$driver];
48:
49: return $resolver();
50: }
51:
52: switch ($driver)
53: {
54: case 'fluent':
55: return new Auth\Drivers\Fluent(Config::get('auth.table'));
56:
57: case 'eloquent':
58: return new Auth\Drivers\Eloquent(Config::get('auth.model'));
59:
60: default:
61: throw new \Exception("Auth driver {$driver} is not supported.");
62: }
63: }
64:
65: /**
66: * Register a third-party authentication driver.
67: *
68: * @param string $driver
69: * @param Closure $resolver
70: * @return void
71: */
72: public static function extend($driver, Closure $resolver)
73: {
74: static::$registrar[$driver] = $resolver;
75: }
76:
77: /**
78: * Magic Method for calling the methods on the default cache driver.
79: *
80: * <code>
81: * // Call the "user" method on the default auth driver
82: * $user = Auth::user();
83: *
84: * // Call the "check" method on the default auth driver
85: * Auth::check();
86: * </code>
87: */
88: public static function __callStatic($method, $parameters)
89: {
90: return call_user_func_array(array(static::driver(), $method), $parameters);
91: }
92:
93: }