1 |
cb15593b
|
Cajova-Houba
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace Illuminate\Auth;
|
4 |
|
|
|
5 |
|
|
use InvalidArgumentException;
|
6 |
|
|
|
7 |
|
|
trait CreatesUserProviders
|
8 |
|
|
{
|
9 |
|
|
/**
|
10 |
|
|
* The registered custom provider creators.
|
11 |
|
|
*
|
12 |
|
|
* @var array
|
13 |
|
|
*/
|
14 |
|
|
protected $customProviderCreators = [];
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
* Create the user provider implementation for the driver.
|
18 |
|
|
*
|
19 |
|
|
* @param string $provider
|
20 |
|
|
* @return \Illuminate\Contracts\Auth\UserProvider
|
21 |
|
|
*
|
22 |
|
|
* @throws \InvalidArgumentException
|
23 |
|
|
*/
|
24 |
|
|
public function createUserProvider($provider)
|
25 |
|
|
{
|
26 |
|
|
$config = $this->app['config']['auth.providers.'.$provider];
|
27 |
|
|
|
28 |
|
|
if (isset($this->customProviderCreators[$config['driver']])) {
|
29 |
|
|
return call_user_func(
|
30 |
|
|
$this->customProviderCreators[$config['driver']], $this->app, $config
|
31 |
|
|
);
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
switch ($config['driver']) {
|
35 |
|
|
case 'database':
|
36 |
|
|
return $this->createDatabaseProvider($config);
|
37 |
|
|
case 'eloquent':
|
38 |
|
|
return $this->createEloquentProvider($config);
|
39 |
|
|
default:
|
40 |
|
|
throw new InvalidArgumentException("Authentication user provider [{$config['driver']}] is not defined.");
|
41 |
|
|
}
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* Create an instance of the database user provider.
|
46 |
|
|
*
|
47 |
|
|
* @param array $config
|
48 |
|
|
* @return \Illuminate\Auth\DatabaseUserProvider
|
49 |
|
|
*/
|
50 |
|
|
protected function createDatabaseProvider($config)
|
51 |
|
|
{
|
52 |
|
|
$connection = $this->app['db']->connection();
|
53 |
|
|
|
54 |
|
|
return new DatabaseUserProvider($connection, $this->app['hash'], $config['table']);
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
/**
|
58 |
|
|
* Create an instance of the Eloquent user provider.
|
59 |
|
|
*
|
60 |
|
|
* @param array $config
|
61 |
|
|
* @return \Illuminate\Auth\EloquentUserProvider
|
62 |
|
|
*/
|
63 |
|
|
protected function createEloquentProvider($config)
|
64 |
|
|
{
|
65 |
|
|
return new EloquentUserProvider($this->app['hash'], $config['model']);
|
66 |
|
|
}
|
67 |
|
|
}
|