Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 166a359

Browse files
committed
added Check\GuzzleHttpService
1 parent 5707316 commit 166a359

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
"require-dev": {
2121
"zendframework/zend-loader" : "2.*",
2222
"sensiolabs/security-checker": "1.3.*@dev",
23-
"symfony/yaml": "v2.3.11"
23+
"symfony/yaml": "v2.3.11",
24+
"guzzle/http" : "3.*"
2425
},
2526
"suggest" : {
2627
"ext-bcmath" : "Required by Check\\CpuPerformance",
2728
"sensiolabs/security-checker": "Required by Check\\SecurityAdvisory",
28-
"symfony/yaml": "Required by Check\\YamlFile"
29+
"symfony/yaml": "Required by Check\\YamlFile",
30+
"guzzle/http": "Required by Check\\GuzzleHttpService"
2931
},
3032
"extra": {
3133
"branch-alias": {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* @license http://framework.zend.com/license/new-bsd New BSD License
4+
*/
5+
6+
namespace ZendDiagnostics\Check;
7+
8+
use Guzzle\Http\Client;
9+
use Guzzle\Http\ClientInterface;
10+
use ZendDiagnostics\Result\Failure;
11+
use ZendDiagnostics\Result\Success;
12+
13+
class GuzzleHttpService extends AbstractCheck
14+
{
15+
protected $url;
16+
protected $headers;
17+
protected $statusCode;
18+
protected $content;
19+
protected $guzzle;
20+
21+
/**
22+
* @param string $url The absolute url to check
23+
* @param array $headers An array of headers used to create the request
24+
* @param array $options An array of guzzle options used to create the request
25+
* @param int $statusCode The response status code to check
26+
* @param null $content The response content to check
27+
* @param ClientInterface $guzzle Instance of guzzle to use
28+
*/
29+
public function __construct($url, array $headers = array(), array $options = array(), $statusCode = 200, $content = null, ClientInterface $guzzle = null)
30+
{
31+
$this->url = $url;
32+
$this->headers = $headers;
33+
$this->options = $options;
34+
$this->statusCode = $statusCode;
35+
$this->content = $content;
36+
37+
if (!$guzzle) {
38+
$guzzle = new Client();
39+
}
40+
41+
$this->guzzle = $guzzle;
42+
}
43+
44+
/**
45+
* @see ZendDiagnostics\CheckInterface::check()
46+
*/
47+
public function check()
48+
{
49+
$response = $this->guzzle->get($this->url, $this->headers, $this->options)->send();
50+
51+
if ($this->statusCode !== $response->getStatusCode()) {
52+
return new Failure("Status code {$this->statusCode} does not match response from {$this->url}");
53+
}
54+
55+
if ($this->content && !strpos($response->getBody(true), $this->content)) {
56+
return new Failure("Content {$this->content} not found in response from {$this->url}");
57+
}
58+
59+
return new Success();
60+
}
61+
}

0 commit comments

Comments
 (0)