1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MadWeb\SocialAuth\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
|
9
|
|
|
class AddSocialProviderCommand extends Command |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The name and signature of the console command. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'social-auth:add'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create social provider in the database.'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Execute the console command. |
27
|
|
|
* |
28
|
|
|
* @return mixed |
29
|
|
|
*/ |
30
|
|
|
public function handle() |
31
|
|
|
{ |
32
|
|
|
$social_model = config('social-auth.models.social'); |
33
|
|
|
|
34
|
|
|
$slug = $this->argument('slug'); |
35
|
|
|
$data = [ |
36
|
|
|
'slug' => $slug, |
37
|
|
|
'label' => ($label = $this->option('label')) ? $label : ucfirst($slug), |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
if ($scopes = $this->option('scopes')) { |
41
|
|
|
$data['scopes'] = $scopes; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
if ($params = $this->option('params')) { |
45
|
|
|
foreach ($params as $idx => $param) { |
|
|
|
|
46
|
|
|
list($key, $value) = explode(':', $param); |
47
|
|
|
unset($params[$idx]); |
48
|
|
|
$params[$key] = $value; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$data['parameters'] = $params; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($override_scopes = $this->option('override_scopes')) { |
55
|
|
|
$data['override_scopes'] = $override_scopes; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if ($stateless = $this->option('stateless')) { |
59
|
|
|
$data['stateless'] = $stateless; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$social_model::create($data); |
63
|
|
|
|
64
|
|
|
$this->info("Social provider '$slug' successfully added to the database."); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the console command arguments. |
69
|
|
|
* |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
|
|
protected function getArguments() |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
|
|
['slug', InputArgument::REQUIRED, 'The name of social provider.'], |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the console command options. |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
protected function getOptions() |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
|
|
['label', 'l', InputOption::VALUE_OPTIONAL, 'Set label of the social provider.'], |
88
|
|
|
|
89
|
|
|
['scopes', 's', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Social provider scopes.'], |
90
|
|
|
|
91
|
|
|
[ |
92
|
|
|
'params', |
93
|
|
|
'p', |
94
|
|
|
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, |
95
|
|
|
'Social provider additional parameters.', |
96
|
|
|
], |
97
|
|
|
|
98
|
|
|
['override_scopes', 'o', InputOption::VALUE_NONE, 'Set social provider scopes should override default.'], |
99
|
|
|
|
100
|
|
|
['stateless', 't', InputOption::VALUE_NONE, 'Social provider should use stateless login.'], |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.