-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
HoneypotServiceProvider.php
51 lines (41 loc) · 1.42 KB
/
HoneypotServiceProvider.php
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
<?php
namespace Spatie\Honeypot;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\View;
use Spatie\Honeypot\SpamResponder\SpamResponder;
use Spatie\Honeypot\View\HoneypotComponent;
use Spatie\Honeypot\View\HoneypotViewComposer;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
class HoneypotServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
$package
->name('laravel-honeypot')
->hasConfigFile()
->hasViews();
}
public function packageBooted()
{
$this
->registerBindings()
->registerBladeClasses();
}
protected function registerBindings(): self
{
$this->app->bind(SpamResponder::class, config('honeypot.respond_to_spam_with'));
$this->app->bind(SpamProtection::class, config('honeypot.spam_protection'));
$this->app->bind(Honeypot::class, fn () => new Honeypot(config('honeypot')));
return $this;
}
protected function registerBladeClasses(): self
{
View::composer('honeypot::honeypotFormFields', HoneypotViewComposer::class);
Blade::component('honeypot', HoneypotComponent::class);
Blade::directive('honeypot', function () {
return "<?php echo view('honeypot::honeypotFormFields'); ?>";
});
return $this;
}
}