Completed
Push — locale-in-url ( f95194...93251b )
by Kamil
21:02
created

ResourceControllerEvent::hasResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ResourceBundle\Event;
13
14
use Symfony\Component\EventDispatcher\GenericEvent;
15
use Symfony\Component\HttpFoundation\Response;
16
17
/**
18
 * @author Jérémy Leherpeur <[email protected]>
19
 */
20
class ResourceControllerEvent extends GenericEvent
21
{
22
    const TYPE_ERROR = 'error';
23
    const TYPE_WARNING = 'warning';
24
    const TYPE_INFO = 'info';
25
    const TYPE_SUCCESS = 'success';
26
27
    /**
28
     * @var string
29
     */
30
    private $messageType = '';
31
32
    /**
33
     * @var string
34
     */
35
    private $message = '';
36
37
    /**
38
     * @var array
39
     */
40
    private $messageParameters = [];
41
42
    /**
43
     * @var int
44
     */
45
    private $errorCode = 500;
46
47
    /**
48
     * @var Response
49
     */
50
    private $response;
51
52
    /**
53
     * @param string $message
54
     * @param string $type
55
     * @param array $parameters
56
     * @param int $errorCode
57
     */
58
    public function stop($message, $type = self::TYPE_ERROR, $parameters = [], $errorCode = 500)
59
    {
60
        $this->messageType = $type;
61
        $this->message = $message;
62
        $this->messageParameters = $parameters;
63
        $this->errorCode = $errorCode;
64
65
        $this->stopPropagation();
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isStopped()
72
    {
73
        return $this->isPropagationStopped();
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getMessageType()
80
    {
81
        return $this->messageType;
82
    }
83
84
    /**
85
     * @param string $messageType Should be one of ResourceEvent's TYPE constants
86
     */
87
    public function setMessageType($messageType)
88
    {
89
        $this->messageType = $messageType;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getMessage()
96
    {
97
        return $this->message;
98
    }
99
100
    /**
101
     * @param string $message
102
     */
103
    public function setMessage($message)
104
    {
105
        $this->message = $message;
106
    }
107
108
    /**
109
     * @return array
110
     */
111
    public function getMessageParameters()
112
    {
113
        return $this->messageParameters;
114
    }
115
116
    /**
117
     * @param array $messageParameters
118
     */
119
    public function setMessageParameters(array $messageParameters)
120
    {
121
        $this->messageParameters = $messageParameters;
122
    }
123
124
    /**
125
     * @return int
126
     */
127
    public function getErrorCode()
128
    {
129
        return $this->errorCode;
130
    }
131
132
    /**
133
     * @param int $errorCode
134
     */
135
    public function setErrorCode($errorCode)
136
    {
137
        $this->errorCode = $errorCode;
138
    }
139
140
    /**
141
     * @param Response $response
142
     */
143
    public function setResponse(Response $response)
144
    {
145
        $this->response = $response;
146
    }
147
148
    /**
149
     * @return bool
150
     */
151
    public function hasResponse()
152
    {
153
        return null !== $this->response;
154
    }
155
156
    /**
157
     * @return Response
158
     */
159
    public function getResponse()
160
    {
161
        return $this->response;
162
    }
163
}
164