|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace DanBettles\Defence\Handler; |
|
6
|
|
|
|
|
7
|
|
|
use DanBettles\Defence\Envelope; |
|
8
|
|
|
use DanBettles\Defence\PhpFunctionsWrapper; |
|
9
|
|
|
use DanBettles\Defence\Factory\HttpResponseFactory; |
|
10
|
|
|
|
|
11
|
|
|
class TerminateScriptHandler implements HandlerInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** @var PhpFunctionsWrapper */ |
|
14
|
|
|
private $phpFunctions; |
|
15
|
|
|
|
|
16
|
|
|
/** @var HttpResponseFactory */ |
|
17
|
|
|
private $httpResponseFactory; |
|
18
|
|
|
|
|
19
|
4 |
|
public function __construct(PhpFunctionsWrapper $phpFunctions, HttpResponseFactory $httpResponseFactory) |
|
20
|
|
|
{ |
|
21
|
4 |
|
$this |
|
22
|
4 |
|
->setPhpFunctionsWrapper($phpFunctions) |
|
23
|
4 |
|
->setHttpResponseFactory($httpResponseFactory) |
|
24
|
4 |
|
; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
4 |
|
private function setPhpFunctionsWrapper(PhpFunctionsWrapper $phpFunctions): self |
|
28
|
|
|
{ |
|
29
|
4 |
|
$this->phpFunctions = $phpFunctions; |
|
30
|
|
|
|
|
31
|
4 |
|
return $this; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
2 |
|
public function getPhpFunctionsWrapper(): PhpFunctionsWrapper |
|
35
|
|
|
{ |
|
36
|
2 |
|
return $this->phpFunctions; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
4 |
|
private function setHttpResponseFactory(HttpResponseFactory $httpResponseFactory): self |
|
40
|
|
|
{ |
|
41
|
4 |
|
$this->httpResponseFactory = $httpResponseFactory; |
|
42
|
|
|
|
|
43
|
4 |
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
2 |
|
public function getHttpResponseFactory(): HttpResponseFactory |
|
47
|
|
|
{ |
|
48
|
2 |
|
return $this->httpResponseFactory; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @return never |
|
53
|
|
|
*/ |
|
54
|
1 |
|
public function __invoke(Envelope $envelope) |
|
55
|
|
|
{ |
|
56
|
1 |
|
$this |
|
57
|
1 |
|
->getHttpResponseFactory() |
|
58
|
1 |
|
->createForbiddenResponse( |
|
59
|
1 |
|
"We're not going to handle your request because it looks suspicious. " . |
|
60
|
1 |
|
"Please contact us if we've made a mistake." |
|
61
|
1 |
|
) |
|
62
|
1 |
|
->prepare($envelope->getRequest()) |
|
63
|
1 |
|
->send() |
|
64
|
1 |
|
; |
|
65
|
|
|
|
|
66
|
1 |
|
$this |
|
67
|
1 |
|
->getPhpFunctionsWrapper() |
|
68
|
1 |
|
->exit() |
|
69
|
1 |
|
; |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|