|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the `tvi/monitor-bundle` project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) https://github.com/turnaev/monitor-bundle/graphs/contributors |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE.md |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
namespace Tvi\MonitorBundle\Check\http\GuzzleHttpService; |
|
13
|
|
|
|
|
14
|
|
|
use JMS\Serializer\Annotation as JMS; |
|
15
|
|
|
use GuzzleHttp\ClientInterface as GuzzleClientInterface; |
|
16
|
|
|
use GuzzleHttp\Message\RequestInterface as GuzzleRequestInterface; |
|
|
|
|
|
|
17
|
|
|
use InvalidArgumentException; |
|
18
|
|
|
use Psr\Http\Message\RequestInterface as PsrRequestInterface; |
|
19
|
|
|
use Tvi\MonitorBundle\Check\CheckAbstract; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
|
|
|
|
|
22
|
|
|
* @JMS\ExclusionPolicy("all") |
|
23
|
|
|
* |
|
24
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
25
|
|
|
*/ |
|
|
|
|
|
|
26
|
|
|
class Check extends CheckAbstract |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
|
|
|
|
|
29
|
|
|
* @var GuzzleHttpService |
|
30
|
|
|
*/ |
|
31
|
|
|
private $checker; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
|
|
|
|
|
34
|
|
|
* @param string|PsrRequestInterface|GuzzleRequestInterface $requestOrUrl |
|
|
|
|
|
|
35
|
|
|
* The absolute url to check, or a |
|
36
|
|
|
* fully-formed request instance |
|
37
|
|
|
* @param array $headers An array of headers used to create the |
|
38
|
|
|
* request |
|
39
|
|
|
* @param array $options An array of guzzle options to use when |
|
40
|
|
|
* sending the request |
|
41
|
|
|
* @param int $statusCode The response status code to check |
|
42
|
|
|
* @param null $content The response content to check |
|
|
|
|
|
|
43
|
|
|
* @param null|GuzzleClientInterface $guzzle Instance of guzzle to use |
|
44
|
|
|
* @param string $method The method of the request |
|
45
|
|
|
* @param mixed $body The body of the request (used for POST, |
|
46
|
|
|
* PUT and DELETE requests) |
|
47
|
|
|
* @param bool $setData set data to result |
|
48
|
|
|
* |
|
49
|
|
|
* @throws InvalidArgumentException |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function __construct( |
|
52
|
|
|
$requestOrUrl, |
|
53
|
|
|
array $headers = [], |
|
54
|
|
|
array $options = [], |
|
55
|
|
|
$statusCode = 200, |
|
56
|
|
|
$content = null, |
|
57
|
|
|
$guzzle = null, |
|
58
|
|
|
$method = 'GET', |
|
59
|
|
|
$body = null, |
|
60
|
|
|
$setData = false) |
|
|
|
|
|
|
61
|
|
|
{ |
|
|
|
|
|
|
62
|
2 |
|
$this->checker = new GuzzleHttpService($requestOrUrl, $headers, $options, $statusCode, $content, $guzzle, $method, $body, $setData); |
|
63
|
2 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
|
|
|
|
|
68
|
2 |
|
public function check() |
|
69
|
|
|
{ |
|
70
|
2 |
|
return $this->checker->check(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|