1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Ivory Http Adapter package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Ivory\HttpAdapter\Event; |
13
|
|
|
|
14
|
|
|
use Ivory\HttpAdapter\HttpAdapterException; |
15
|
|
|
use Ivory\HttpAdapter\HttpAdapterInterface; |
16
|
|
|
use Ivory\HttpAdapter\Message\InternalRequestInterface; |
17
|
|
|
use Ivory\HttpAdapter\Message\ResponseInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
class RequestCreatedEvent extends AbstractEvent |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var InternalRequestInterface |
26
|
|
|
*/ |
27
|
|
|
private $request; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var ResponseInterface|null |
31
|
|
|
*/ |
32
|
|
|
private $response; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var HttpAdapterException|null |
36
|
|
|
*/ |
37
|
|
|
private $exception; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param HttpAdapterInterface $httpAdapter |
41
|
|
|
* @param InternalRequestInterface $request |
42
|
|
|
*/ |
43
|
180 |
|
public function __construct(HttpAdapterInterface $httpAdapter, InternalRequestInterface $request) |
44
|
|
|
{ |
45
|
180 |
|
parent::__construct($httpAdapter); |
46
|
|
|
|
47
|
180 |
|
$this->setRequest($request); |
48
|
180 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return InternalRequestInterface |
52
|
|
|
*/ |
53
|
162 |
|
public function getRequest() |
54
|
|
|
{ |
55
|
162 |
|
return $this->request; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param InternalRequestInterface $request |
60
|
|
|
*/ |
61
|
180 |
|
public function setRequest(InternalRequestInterface $request) |
62
|
|
|
{ |
63
|
180 |
|
$this->request = $request; |
64
|
180 |
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return bool |
68
|
|
|
*/ |
69
|
72 |
|
public function hasResponse() |
70
|
|
|
{ |
71
|
72 |
|
return $this->response !== null; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return ResponseInterface|null |
76
|
|
|
*/ |
77
|
54 |
|
public function getResponse() |
78
|
|
|
{ |
79
|
54 |
|
return $this->response; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param ResponseInterface|null $response |
84
|
|
|
*/ |
85
|
27 |
|
public function setResponse(ResponseInterface $response = null) |
86
|
|
|
{ |
87
|
27 |
|
$this->response = $response; |
88
|
27 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return bool |
92
|
|
|
*/ |
93
|
81 |
|
public function hasException() |
94
|
|
|
{ |
95
|
81 |
|
return $this->exception !== null; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return HttpAdapterException|null |
100
|
|
|
*/ |
101
|
54 |
|
public function getException() |
102
|
|
|
{ |
103
|
54 |
|
return $this->exception; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param HttpAdapterException|null $exception |
108
|
|
|
*/ |
109
|
27 |
|
public function setException(HttpAdapterException $exception = null) |
110
|
|
|
{ |
111
|
27 |
|
$this->exception = $exception; |
112
|
27 |
|
} |
113
|
|
|
} |
114
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.