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