Passed
Push — master ( 41129c...97589e )
by Iman
08:01
created

Reactions::afterCalling()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
7
class Reactions
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
    public function __construct(Chain $chain)
20
    {
21
        $this->chain = $chain;
22
    }
23
24
    public function response(): Responder
25
    {
26
        return new Responder($this->chain, $this);
27
    }
28
29
    public function redirect(): Redirector
30
    {
31
        return new Redirector($this->chain, $this);
32
    }
33
34
    public function afterCalling($callback, array $parameters = []): Reactions
35
    {
36
        $this->chain->addAfterCall($callback, $parameters);
37
38
        return $this;
39
    }
40
41
    public function weThrowNew(string $exception, string $message = '')
42
    {
43
        $this->chain->addException($exception, $message);
44
    }
45
46
    public function abort($code, string $message = '', array $headers = [])
47
    {
48
        $this->chain->addAbort($code, $message, $headers);
49
    }
50
51
    public function weDenyAccess(string $message = '')
52
    {
53
        $this->chain->addException(AuthorizationException::class, $message);
54
    }
55
56
    public function afterFiringEvent($event, $payload = [], $halt = false): Reactions
57
    {
58
        $this->chain->eventFire($event, $payload, $halt);
59
60
        return $this;
61
    }
62
63
    public function __destruct()
64
    {
65
        app(Chain::class)->submitChainConfig();
66
    }
67
}
68