1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Acacha\LaravelSocial\Providers; |
4
|
|
|
|
5
|
|
|
use Acacha\LaravelSocial\Facades\LaravelSocial; |
6
|
|
|
use Acacha\LaravelSocial\Repositories\EloquentSocialUserRepository; |
7
|
|
|
use Acacha\LaravelSocial\Repositories\SocialUserRepository; |
8
|
|
|
use Acacha\LaravelSocial\Services\ConfigureSocialServicesManager; |
9
|
|
|
use Acacha\LaravelSocial\Services\LaravelSocialiteService; |
10
|
|
|
use Acacha\LaravelSocial\Services\OAuthApp; |
11
|
|
|
use Acacha\LaravelSocial\SocialProviders\SocialProviderManager; |
12
|
|
|
use Illuminate\Console\DetectsApplicationNamespace; |
13
|
|
|
use Illuminate\Support\ServiceProvider; |
14
|
|
|
use Laravel\Socialite\SocialiteServiceProvider; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class LaravelSocialServiceProvider. |
18
|
|
|
*/ |
19
|
|
|
class LaravelSocialServiceProvider extends ServiceProvider |
20
|
|
|
{ |
21
|
|
|
use DetectsApplicationNamespace; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Enabled social providers. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
public $enabled = ['Github','Facebook','Google','Twitter', 'Linkedin']; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Register the application services. |
32
|
|
|
*/ |
33
|
|
|
public function register() |
34
|
|
|
{ |
35
|
|
|
if (!defined('LARAVELSOCIAL_PATH')) { |
36
|
|
|
define('LARAVELSOCIAL_PATH', realpath(__DIR__.'/../../')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if ($this->app->runningInConsole()) { |
40
|
|
|
$this->commands([\Acacha\LaravelSocial\Console\Commands\Social::class]); |
41
|
|
|
$this->commands([\Acacha\LaravelSocial\Console\Commands\MakeSocial::class]); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$this->app->bind('LaravelSocial', function () { |
45
|
|
|
return new \Acacha\LaravelSocial\LaravelSocial(); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$this->registerSocialiteProvider(); |
49
|
|
|
|
50
|
|
|
$this->registerSocialProviderManager(); |
51
|
|
|
|
52
|
|
|
$this->registerConfigureSocialServicesManager(); |
53
|
|
|
|
54
|
|
|
$this->registerOAuthApp(); |
55
|
|
|
|
56
|
|
|
$this->registerSocialProviders(); |
57
|
|
|
|
58
|
|
|
$this->registerLaravelSocialiteService(); |
59
|
|
|
|
60
|
|
|
$this->registerSocialUsersRepository(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Bootstrap the application services. |
65
|
|
|
*/ |
66
|
|
|
public function boot() |
67
|
|
|
{ |
68
|
|
|
$this->defineRoutes(); |
69
|
|
|
$this->loadMigrations(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Define the AdminLTETemplate routes. |
74
|
|
|
*/ |
75
|
|
|
protected function defineRoutes() |
76
|
|
|
{ |
77
|
|
|
if (!$this->app->routesAreCached()) { |
78
|
|
|
$router = app('router'); |
79
|
|
|
|
80
|
|
|
$router->group(['namespace' => 'Acacha\LaravelSocial\Http\Controllers'], function () { |
81
|
|
|
require __DIR__.'/../Http/routes.php'; |
82
|
|
|
}); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Register social provider manager. |
88
|
|
|
*/ |
89
|
|
|
private function registerSocialProviderManager() |
90
|
|
|
{ |
91
|
|
|
$this->app->singleton(\Acacha\LaravelSocial\Contracts\Factory::class, function ($app) { |
92
|
|
|
return new SocialProviderManager($app); |
93
|
|
|
}); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Register socialite service provider. |
98
|
|
|
*/ |
99
|
|
|
private function registerSocialiteProvider() |
100
|
|
|
{ |
101
|
|
|
$this->app->register(SocialiteServiceProvider::class); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Register configure social services manager. |
106
|
|
|
*/ |
107
|
|
|
private function registerConfigureSocialServicesManager() |
108
|
|
|
{ |
109
|
|
|
$this->app->singleton( |
110
|
|
|
\Acacha\LaravelSocial\Contracts\ConfigureSocialServicesFactory::class, |
111
|
|
|
function ($app) { |
112
|
|
|
return new ConfigureSocialServicesManager($app); |
113
|
|
|
} |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Register OAuth App. |
119
|
|
|
*/ |
120
|
|
|
private function registerOAuthApp() |
121
|
|
|
{ |
122
|
|
|
$oauth = new OAuthApp(); |
123
|
|
|
$this->app->instance(\Acacha\LaravelSocial\Services\OAuthApp::class, $oauth); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Register Laravel Socialite service. |
128
|
|
|
*/ |
129
|
|
|
private function registerLaravelSocialiteService() |
130
|
|
|
{ |
131
|
|
|
$this->app->bind(\Acacha\LaravelSocial\Services\LaravelSocialiteService::class, function ($app) { |
|
|
|
|
132
|
|
|
return new LaravelSocialiteService( |
133
|
|
|
new \Acacha\Filesystem\Compiler\StubFileCompiler(), |
134
|
|
|
new \Acacha\Filesystem\Filesystem() |
135
|
|
|
); |
136
|
|
|
}); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Register social providers. |
141
|
|
|
*/ |
142
|
|
|
private function registerSocialProviders() |
143
|
|
|
{ |
144
|
|
|
foreach ($this->enabled as $provider) { |
145
|
|
|
$providerClass = $provider . 'SocialProvider'; |
146
|
|
|
$this->app->bind($providerClass, function ($app) use ($providerClass) { |
147
|
|
|
$providerClassWithNamespace = 'Acacha\LaravelSocial\SocialProviders\\' . $providerClass; |
148
|
|
|
return new $providerClassWithNamespace($app->make('Laravel\Socialite\Contracts\Factory')); |
149
|
|
|
}); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Load migrations. |
155
|
|
|
*/ |
156
|
|
|
private function loadMigrations() |
157
|
|
|
{ |
158
|
|
|
$this->loadMigrationsFrom(LARAVELSOCIAL_PATH .'/database/migrations'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Register social users repository. |
163
|
|
|
*/ |
164
|
|
|
private function registerSocialUsersRepository() |
165
|
|
|
{ |
166
|
|
|
$this->app->bind( |
167
|
|
|
SocialUserRepository::class, |
168
|
|
|
EloquentSocialUserRepository::class |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.