1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
-
- namespace Illuminate\Auth;
-
- use InvalidArgumentException;
-
- trait CreatesUserProviders
- {
-
-
- protected $customProviderCreators = [];
-
-
-
- public function createUserProvider($provider = null)
- {
- if (is_null($config = $this->getProviderConfiguration($provider))) {
- return;
- }
-
- if (isset($this->customProviderCreators[$driver = ($config['driver'] ?? null)])) {
- return call_user_func(
- $this->customProviderCreators[$driver], $this->app, $config
- );
- }
-
- switch ($driver) {
- case 'database':
- return $this->createDatabaseProvider($config);
- case 'eloquent':
- return $this->createEloquentProvider($config);
- default:
- throw new InvalidArgumentException(
- "Authentication user provider [{$driver}] is not defined."
- );
- }
- }
-
-
-
- protected function getProviderConfiguration($provider)
- {
- if ($provider = $provider ?: $this->getDefaultUserProvider()) {
- return $this->app['config']['auth.providers.'.$provider];
- }
- }
-
-
-
- protected function createDatabaseProvider($config)
- {
- $connection = $this->app['db']->connection();
-
- return new DatabaseUserProvider($connection, $this->app['hash'], $config['table']);
- }
-
-
-
- protected function createEloquentProvider($config)
- {
- return new EloquentUserProvider($this->app['hash'], $config['model']);
- }
-
-
-
- public function getDefaultUserProvider()
- {
- return $this->app['config']['auth.defaults.provider'];
- }
- }
|