1 | <?php |
||
10 | class ConfigRetriever implements ConfigRetrieverInterface |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | protected $providerName; |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $providerIdentifier; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $servicesArray; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $additionalConfigKeys; |
||
31 | |||
32 | /** |
||
33 | 2 | * @param string $providerIdentifier |
|
34 | * @param array $additionalConfigKeys |
||
35 | 2 | * |
|
36 | * @throws \SocialiteProviders\Manager\Exception\MissingConfigException |
||
37 | 2 | * |
|
38 | 2 | * @return \SocialiteProviders\Manager\Contracts\ConfigInterface |
|
39 | 1 | */ |
|
40 | 1 | public function fromEnv($providerIdentifier, array $additionalConfigKeys = []) |
|
41 | { |
||
42 | 1 | $this->providerIdentifier = $providerIdentifier; |
|
43 | 1 | $this->additionalConfigKeys = $additionalConfigKeys; |
|
44 | |||
45 | return new Config( |
||
46 | $this->getFromEnv('KEY'), |
||
47 | $this->getFromEnv('SECRET'), |
||
48 | $this->getFromEnv('REDIRECT_URI'), |
||
49 | $this->getConfigItems($additionalConfigKeys, function ($key) { |
||
50 | return $this->getFromEnv(strtoupper($key)); |
||
51 | })); |
||
52 | } |
||
53 | 2 | ||
54 | /** |
||
55 | 2 | * @param string $providerName |
|
56 | 2 | * @param array $additionalConfigKeys |
|
57 | * |
||
58 | 1 | * @throws \SocialiteProviders\Manager\Exception\MissingConfigException |
|
59 | 1 | * |
|
60 | 1 | * @return \SocialiteProviders\Manager\Contracts\ConfigInterface |
|
61 | 1 | */ |
|
62 | 1 | public function fromServices($providerName, array $additionalConfigKeys = []) |
|
63 | 1 | { |
|
64 | 1 | $this->providerName = $providerName; |
|
65 | $this->getConfigFromServicesArray($providerName); |
||
66 | |||
67 | $this->additionalConfigKeys = $additionalConfigKeys; |
||
68 | |||
69 | return new Config( |
||
70 | $this->getFromServices('client_id'), |
||
71 | $this->getFromServices('client_secret'), |
||
72 | $this->getFromServices('redirect'), |
||
73 | 2 | $this->getConfigItems($additionalConfigKeys, function ($key) { |
|
74 | return $this->getFromServices(strtolower($key)); |
||
75 | 2 | })); |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | 2 | * @param array $configKeys |
|
80 | * @param \Closure $keyRetrievalClosure |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | protected function getConfigItems(array $configKeys, \Closure $keyRetrievalClosure) |
||
92 | 2 | ||
93 | 2 | /** |
|
94 | 2 | * @param array $keys |
|
95 | * @param \Closure $keyRetrievalClosure |
||
96 | 2 | * |
|
97 | * @return array |
||
98 | */ |
||
99 | protected function retrieveItemsFromConfig(array $keys, \Closure $keyRetrievalClosure) |
||
109 | |||
110 | /** |
||
111 | 1 | * @param string $key |
|
112 | * |
||
113 | * @throws \SocialiteProviders\Manager\Exception\MissingConfigException |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | protected function getFromServices($key) |
||
133 | |||
134 | /** |
||
135 | * @param string $key |
||
136 | * |
||
137 | * @throws \SocialiteProviders\Manager\Exception\MissingConfigException |
||
138 | 2 | * |
|
139 | * @return string |
||
140 | 2 | */ |
|
141 | 2 | protected function getFromEnv($key) |
|
162 | |||
163 | /** |
||
164 | * @param string $providerName |
||
165 | * |
||
166 | * @throws \SocialiteProviders\Manager\Exception\MissingConfigException |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | protected function getConfigFromServicesArray($providerName) |
||
192 | |||
193 | /** |
||
194 | * @param string $key |
||
195 | * |
||
196 | * @return bool |
||
197 | */ |
||
198 | protected function isAdditionalConfig($key) |
||
202 | } |
||
203 |