This repository was archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathReCaptchaServiceProvider.php
More file actions
executable file
·125 lines (104 loc) · 2.9 KB
/
ReCaptchaServiceProvider.php
File metadata and controls
executable file
·125 lines (104 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* Copyright (c) 2017 - present
* LaravelGoogleRecaptcha - ReCaptchaServiceProvider.php
* author: Roberto Belotti - [email protected]
* web : robertobelotti.com, github.com/biscolab
* Initial version created on: 12/9/2018
* MIT license: https://github.com/biscolab/laravel-recaptcha/blob/master/LICENSE
*/
namespace Biscolab\ReCaptcha;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
/**
* Class ReCaptchaServiceProvider
* @package Biscolab\ReCaptcha
*/
class ReCaptchaServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
*
*/
public function boot()
{
$this->addValidationRule();
$this->registerRoutes();
$this->publishes([
__DIR__ . '/../config/recaptcha.php' => config_path('recaptcha.php'),
], 'config');
}
/**
* Extends Validator to include a recaptcha type
*/
public function addValidationRule()
{
Validator::extendImplicit(recaptchaRuleName(), function ($attribute, $value) {
return app('recaptcha')->validate($value);
});
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__ . '/../config/recaptcha.php',
'recaptcha'
);
$this->registerReCaptchaBuilder();
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides(): array
{
return ['recaptcha'];
}
/**
* @return ReCaptchaServiceProvider
*
* @since v3.4.1
*/
protected function registerRoutes(): ReCaptchaServiceProvider
{
Route::get(
config('recaptcha.default_validation_route', 'biscolab-recaptcha/validate'),
['uses' => 'Biscolab\ReCaptcha\Controllers\ReCaptchaController@validateV3']
)->middleware('web');
return $this;
}
/**
* Register the HTML builder instance.
*
* @return void
*/
protected function registerReCaptchaBuilder()
{
$this->app->singleton('recaptcha', function ($app) {
$recaptcha_class = '';
switch (config('recaptcha.version')) {
case 'v3':
$recaptcha_class = ReCaptchaBuilderV3::class;
break;
case 'v2':
$recaptcha_class = ReCaptchaBuilderV2::class;
break;
case 'invisible':
$recaptcha_class = ReCaptchaBuilderInvisible::class;
break;
}
return new $recaptcha_class(config('recaptcha.api_site_key'), config('recaptcha.api_secret_key'));
});
}
}