-
-
Notifications
You must be signed in to change notification settings - Fork 566
/
Copy pathProtection.php
90 lines (73 loc) · 1.76 KB
/
Protection.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
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
<?php
namespace Statamic\Auth\Protect;
use InvalidArgumentException;
use Statamic\Contracts\Auth\Protect\Protectable;
use Statamic\Facades\URL;
class Protection
{
protected $data;
protected $manager;
public function __construct(ProtectorManager $manager)
{
$this->manager = $manager;
}
public function setData($data)
{
$this->data = $data;
return $this;
}
public function data()
{
return $this->data;
}
public function scheme()
{
if (
$this->data
&& $this->data instanceof Protectable
&& $scheme = $this->data->getProtectionScheme()
) {
return $scheme;
}
if ($default = config('statamic.protect.default')) {
return $default;
}
return null;
}
public function driver()
{
if (! $scheme = $this->scheme()) {
// No scheme defined, nothing should happen.
return $this->manager->driver('null');
}
try {
return $this->manager->driver($scheme);
} catch (InvalidArgumentException $e) {
$this->log($e->getMessage());
return $this->manager->createFallbackDriver();
}
}
public function protect()
{
$this->driver()
->setUrl($this->url())
->setData($this->data())
->protect();
}
public function cacheable()
{
return $this->driver()
->cacheable();
}
protected function url()
{
return URL::tidy(request()->fullUrl());
}
protected function log($message)
{
\Log::debug(vsprintf('%s Denying access to %s.', [
$message,
$this->url(),
]));
}
}