|
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 ZendDiagnostics\Check\GuzzleHttpService; |
|
20
|
|
|
use Tvi\MonitorBundle\Check\CheckAbstract; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
|
|
|
|
|
23
|
|
|
* @JMS\ExclusionPolicy("all") |
|
24
|
|
|
* |
|
25
|
|
|
* @author Vladimir Turnaev <[email protected]> |
|
26
|
|
|
*/ |
|
|
|
|
|
|
27
|
|
|
class Check extends CheckAbstract |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
|
|
|
|
|
30
|
|
|
* @var GuzzleHttpService |
|
31
|
|
|
*/ |
|
32
|
|
|
private $checker; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** |
|
|
|
|
|
|
35
|
|
|
* @param string|PsrRequestInterface|GuzzleRequestInterface $requestOrUrl |
|
|
|
|
|
|
36
|
|
|
* The absolute url to check, or a |
|
37
|
|
|
* fully-formed request instance |
|
38
|
|
|
* @param array $headers An array of headers used to create the |
|
39
|
|
|
* request |
|
40
|
|
|
* @param array $options An array of guzzle options to use when |
|
41
|
|
|
* sending the request |
|
42
|
|
|
* @param int $statusCode The response status code to check |
|
43
|
|
|
* @param null $content The response content to check |
|
|
|
|
|
|
44
|
|
|
* @param null|GuzzleClientInterface $guzzle Instance of guzzle to use |
|
45
|
|
|
* @param string $method The method of the request |
|
46
|
|
|
* @param mixed $body The body of the request (used for POST, PUT |
|
47
|
|
|
* and DELETE requests) |
|
48
|
|
|
* |
|
49
|
|
|
* @throws InvalidArgumentException |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function __construct($requestOrUrl, array $headers = [], array $options = [], $statusCode = 200, $content = null, $guzzle = null, $method = 'GET', $body = null) |
|
52
|
|
|
{ |
|
53
|
2 |
|
$this->checker = new GuzzleHttpService($requestOrUrl, $headers, $options, $statusCode, $content, $guzzle, $method, $body); |
|
54
|
2 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
|
|
|
|
|
59
|
2 |
|
public function check() |
|
60
|
|
|
{ |
|
61
|
2 |
|
return $this->checker->check(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|