|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Acquia\Hmac\Client; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Command\Guzzle\Parameter; |
|
|
|
|
|
|
6
|
|
|
use GuzzleHttp\Command\Guzzle\ResponseLocation\JsonLocation; |
|
|
|
|
|
|
7
|
|
|
use GuzzleHttp\Command\Guzzle\ResponseLocation\ResponseLocationInterface; |
|
|
|
|
|
|
8
|
|
|
use GuzzleHttp\Command\ResultInterface; |
|
|
|
|
|
|
9
|
|
|
use GuzzleHttp\Exception\InvalidArgumentException; |
|
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class AdaptiveJsonLocation |
|
14
|
|
|
* |
|
15
|
|
|
* While it mostly deals in JSON responses, some APIs appear to deliver a few |
|
16
|
|
|
* non-JSON responses from certain endpoints under certain circumstances. For |
|
17
|
|
|
* example, Acquia Search "ping" endpoints tend to return XML, while the base |
|
18
|
|
|
* Controller Ping endpoint may simply return a string. This class acts as a |
|
19
|
|
|
* safety net; catching any exceptions that our parent JsonLocation might throw |
|
20
|
|
|
* during the course of a non-JSON response, and presenting the string response |
|
21
|
|
|
* from the underlying Guzzle Client. |
|
22
|
|
|
* |
|
23
|
|
|
* @todo |
|
24
|
|
|
* Abandon this class and fallback to normal model-based deserialization when |
|
25
|
|
|
* we can rely on more consistent, documented response types from Search API. |
|
26
|
|
|
*/ |
|
27
|
|
|
class AdaptiveJsonLocation extends JsonLocation implements ResponseLocationInterface |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* {@inheritdoc} |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct($locationName = 'adaptivejson') |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($locationName); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public function before(ResultInterface $result, ResponseInterface $response, Parameter $model) |
|
41
|
|
|
{ |
|
42
|
|
|
try { |
|
43
|
|
|
return parent::before($result, $response, $model); |
|
44
|
|
|
} catch (InvalidArgumentException $e) { |
|
45
|
|
|
return $result; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* {@inheritdoc} |
|
51
|
|
|
*/ |
|
52
|
|
|
public function after(ResultInterface $result, ResponseInterface $response, Parameter $model) |
|
53
|
|
|
{ |
|
54
|
|
|
try { |
|
55
|
|
|
// First, check for valid JSON. If we can return that, then great! |
|
56
|
|
|
$output = parent::after($result, $response, $model); |
|
57
|
|
|
$result['response'] = ($output === $result) ? (string) $response->getBody() : $output; |
|
58
|
|
|
} catch (InvalidArgumentException $e) { |
|
59
|
|
|
// If the endpoint we're dealing with returns something that isn't |
|
60
|
|
|
// valid JSON, pass it on under the "response" key. |
|
61
|
|
|
$result['response'] = (string) $response->getBody(); |
|
62
|
|
|
} |
|
63
|
|
|
return $result; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths