1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Imanghafoori\HeyMan\Reactions; |
4
|
|
|
|
5
|
|
|
use Illuminate\Auth\Access\AuthorizationException; |
6
|
|
|
use Imanghafoori\HeyMan\Chain; |
7
|
|
|
|
8
|
|
|
class Reactions |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var \Imanghafoori\HeyMan\Chain |
12
|
|
|
*/ |
13
|
|
|
private $chain; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Actions constructor. |
17
|
|
|
* |
18
|
|
|
* @param \Imanghafoori\HeyMan\Chain $chain |
19
|
|
|
*/ |
20
|
|
|
public function __construct(Chain $chain) |
21
|
|
|
{ |
22
|
|
|
$this->chain = $chain; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function response(): Responder |
26
|
|
|
{ |
27
|
|
|
return new Responder($this->chain, $this); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function redirect(): Redirector |
31
|
|
|
{ |
32
|
|
|
return new Redirector($this->chain, $this); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function afterCalling($callback, array $parameters = []): self |
36
|
|
|
{ |
37
|
|
|
$this->chain->addAfterCall($callback, $parameters); |
38
|
|
|
|
39
|
|
|
return $this; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function weThrowNew(string $exception, string $message = '') |
43
|
|
|
{ |
44
|
|
|
$this->chain->addException($exception, $message); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function abort($code, string $message = '', array $headers = []) |
48
|
|
|
{ |
49
|
|
|
$this->chain->addAbort($code, $message, $headers); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function weRespondFrom($callback, array $parameters = []) |
53
|
|
|
{ |
54
|
|
|
$this->chain->addRespondFrom($callback, $parameters); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function weDenyAccess(string $message = '') |
58
|
|
|
{ |
59
|
|
|
$this->chain->addException(AuthorizationException::class, $message); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function afterFiringEvent($event, $payload = [], $halt = false): self |
63
|
|
|
{ |
64
|
|
|
$this->chain->eventFire($event, $payload, $halt); |
65
|
|
|
|
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function __destruct() |
70
|
|
|
{ |
71
|
|
|
app(Chain::class)->submitChainConfig(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|