1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Veslo project <https://github.com/symfony-doge/veslo>. |
5
|
|
|
* |
6
|
|
|
* (C) 2019 Pavel Petrov <[email protected]>. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 GPL-3.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
declare(strict_types=1); |
15
|
|
|
|
16
|
|
|
namespace Veslo\AppBundle\Event\Http\Client; |
17
|
|
|
|
18
|
|
|
use GuzzleHttp\ClientInterface as HttpClientInterface; |
19
|
|
|
use GuzzleHttp\Exception\ConnectException; |
20
|
|
|
use Symfony\Component\EventDispatcher\Event; |
21
|
|
|
use Veslo\AppBundle\Http\Client\Batman; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Some HTTP clients can propagate it whenever they failed to establish a connection to website |
25
|
|
|
* |
26
|
|
|
* @see Batman::request() |
27
|
|
|
*/ |
28
|
|
|
class ConnectFailedEvent extends Event |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Event name |
32
|
|
|
* |
33
|
|
|
* @const string |
34
|
|
|
*/ |
35
|
|
|
public const NAME = 'veslo.app.event.http.client.connect_failed'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The HTTP Client that failed to send a request |
39
|
|
|
* |
40
|
|
|
* @var HttpClientInterface |
41
|
|
|
*/ |
42
|
|
|
private $client; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Connect exception to analyse |
46
|
|
|
* |
47
|
|
|
* @var ConnectException |
48
|
|
|
*/ |
49
|
|
|
private $connectException; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* ConnectFailedEvent constructor. |
53
|
|
|
* |
54
|
|
|
* @param HttpClientInterface $client The HTTP Client that failed to send a request |
55
|
|
|
* @param ConnectException $connectException Connect exception to analyse |
56
|
|
|
*/ |
57
|
|
|
public function __construct(HttpClientInterface $client, ConnectException $connectException) |
58
|
|
|
{ |
59
|
|
|
$this->client = $client; |
60
|
|
|
$this->connectException = $connectException; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns the HTTP Client that failed to send a request |
65
|
|
|
* |
66
|
|
|
* @return HttpClientInterface |
67
|
|
|
*/ |
68
|
|
|
public function getClient(): HttpClientInterface |
69
|
|
|
{ |
70
|
|
|
return $this->client; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns a connect exception to analyse |
75
|
|
|
* |
76
|
|
|
* @return ConnectException |
77
|
|
|
*/ |
78
|
|
|
public function getConnectException(): ConnectException |
79
|
|
|
{ |
80
|
|
|
return $this->connectException; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|