Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Auth\Access;
4
 
5
use Exception;
6
use Throwable;
7
 
8
class AuthorizationException extends Exception
9
{
10
    /**
11
     * The response from the gate.
12
     *
13
     * @var \Illuminate\Auth\Access\Response
14
     */
15
    protected $response;
16
 
17
    /**
18
     * The HTTP response status code.
19
     *
20
     * @var int|null
21
     */
22
    protected $status;
23
 
24
    /**
25
     * Create a new authorization exception instance.
26
     *
27
     * @param  string|null  $message
28
     * @param  mixed  $code
29
     * @param  \Throwable|null  $previous
30
     * @return void
31
     */
32
    public function __construct($message = null, $code = null, Throwable $previous = null)
33
    {
34
        parent::__construct($message ?? 'This action is unauthorized.', 0, $previous);
35
 
36
        $this->code = $code ?: 0;
37
    }
38
 
39
    /**
40
     * Get the response from the gate.
41
     *
42
     * @return \Illuminate\Auth\Access\Response
43
     */
44
    public function response()
45
    {
46
        return $this->response;
47
    }
48
 
49
    /**
50
     * Set the response from the gate.
51
     *
52
     * @param  \Illuminate\Auth\Access\Response  $response
53
     * @return $this
54
     */
55
    public function setResponse($response)
56
    {
57
        $this->response = $response;
58
 
59
        return $this;
60
    }
61
 
62
    /**
63
     * Set the HTTP response status code.
64
     *
65
     * @param  int|null  $status
66
     * @return $this
67
     */
68
    public function withStatus($status)
69
    {
70
        $this->status = $status;
71
 
72
        return $this;
73
    }
74
 
75
    /**
76
     * Set the HTTP response status code to 404.
77
     *
78
     * @return $this
79
     */
80
    public function asNotFound()
81
    {
82
        return $this->withStatus(404);
83
    }
84
 
85
    /**
86
     * Determine if the HTTP status code has been set.
87
     *
88
     * @return bool
89
     */
90
    public function hasStatus()
91
    {
92
        return $this->status !== null;
93
    }
94
 
95
    /**
96
     * Get the HTTP status code.
97
     *
98
     * @return int|null
99
     */
100
    public function status()
101
    {
102
        return $this->status;
103
    }
104
 
105
    /**
106
     * Create a deny response object from this exception.
107
     *
108
     * @return \Illuminate\Auth\Access\Response
109
     */
110
    public function toResponse()
111
    {
112
        return Response::deny($this->message, $this->code)->withStatus($this->status);
113
    }
114
}