1
|
|
|
<?php namespace Arcanedev\NoCaptcha; |
2
|
|
|
|
3
|
|
|
use Illuminate\Support\Manager; |
4
|
|
|
use Arcanedev\NoCaptcha\Contracts\{ |
5
|
|
|
NoCaptchaManager as NoCaptchaManagerContract, |
6
|
|
|
NoCaptcha as NoCaptchaContract, |
7
|
|
|
}; |
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class NoCaptchaManager |
11
|
|
|
* |
12
|
|
|
* @package Arcanedev\NoCaptcha |
13
|
|
|
* @author ARCANEDEV <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class NoCaptchaManager extends Manager implements NoCaptchaManagerContract |
16
|
|
|
{ |
17
|
|
|
/* ----------------------------------------------------------------- |
18
|
|
|
| Getters |
19
|
|
|
| ----------------------------------------------------------------- |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get the default driver name. |
24
|
|
|
* |
25
|
|
|
* @return string |
26
|
|
|
*/ |
27
|
2 |
|
public function getDefaultDriver(): string |
28
|
|
|
{ |
29
|
2 |
|
return $this->config('version'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/* ----------------------------------------------------------------- |
33
|
|
|
| Main Methods |
34
|
|
|
| ----------------------------------------------------------------- |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get the NoCaptcha driver by the given version. |
39
|
|
|
* |
40
|
|
|
* @param string|null $version |
41
|
|
|
* |
42
|
|
|
* @return \Arcanedev\NoCaptcha\NoCaptchaV3|\Arcanedev\NoCaptcha\NoCaptchaV2 |
43
|
|
|
*/ |
44
|
16 |
|
public function version($version = null): NoCaptchaContract |
45
|
|
|
{ |
46
|
16 |
|
return $this->driver($version); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Create the v2 captcha. |
51
|
|
|
* |
52
|
|
|
* @return \Arcanedev\NoCaptcha\NoCaptchaV2 |
53
|
|
|
*/ |
54
|
2 |
|
public function createV2Driver(): NoCaptchaContract |
55
|
|
|
{ |
56
|
2 |
|
return $this->buildDriver(NoCaptchaV2::class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Create the v3 captcha. |
61
|
|
|
* |
62
|
|
|
* @return \Arcanedev\NoCaptcha\NoCaptchaV3 |
63
|
|
|
*/ |
64
|
14 |
|
public function createV3Driver(): NoCaptchaContract |
65
|
|
|
{ |
66
|
14 |
|
return $this->buildDriver(NoCaptchaV3::class); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/* ----------------------------------------------------------------- |
70
|
|
|
| Other Methods |
71
|
|
|
| ----------------------------------------------------------------- |
72
|
|
|
*/ |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Build a driver. |
76
|
|
|
* |
77
|
|
|
* @param string $driver |
78
|
|
|
* |
79
|
|
|
* @return \Arcanedev\NoCaptcha\Contracts\NoCaptcha |
80
|
|
|
*/ |
81
|
14 |
|
protected function buildDriver(string $driver): NoCaptchaContract |
82
|
|
|
{ |
83
|
14 |
|
return $this->container->make($driver, [ |
84
|
14 |
|
'secret' => $this->config('secret'), |
85
|
14 |
|
'siteKey' => $this->config('sitekey'), |
86
|
14 |
|
'locale' => $this->config('lang') ?: $this->container->getLocale(), |
87
|
|
|
]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get a value from the config file. |
92
|
|
|
* |
93
|
|
|
* @param string $key |
94
|
|
|
* |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
14 |
|
protected function config(string $key = '') |
98
|
|
|
{ |
99
|
14 |
|
return $this->container['config']->get("no-captcha.{$key}"); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|