/usr/share/php/Guzzle/Service/Command/LocationVisitor/Response/JsonVisitor.php is in php-guzzle 3.7.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | <?php
namespace Guzzle\Service\Command\LocationVisitor\Response;
use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;
/**
* Location visitor used to marshal JSON response data into a formatted array.
*
* Allows top level JSON parameters to be inserted into the result of a command. The top level attributes are grabbed
* from the response's JSON data using the name value by default. Filters can be applied to parameters as they are
* traversed. This allows data to be normalized before returning it to users (for example converting timestamps to
* DateTime objects).
*/
class JsonVisitor extends AbstractResponseVisitor
{
public function before(CommandInterface $command, array &$result)
{
// Ensure that the result of the command is always rooted with the parsed JSON data
$result = $command->getResponse()->json();
}
public function visit(
CommandInterface $command,
Response $response,
Parameter $param,
&$value,
$context = null
) {
$name = $param->getName();
$key = $param->getWireName();
if (isset($value[$key])) {
$this->recursiveProcess($param, $value[$key]);
if ($key != $name) {
$value[$name] = $value[$key];
unset($value[$key]);
}
}
}
/**
* Recursively process a parameter while applying filters
*
* @param Parameter $param API parameter being validated
* @param mixed $value Value to validate and process. The value may change during this process.
*/
protected function recursiveProcess(Parameter $param, &$value)
{
if ($value === null) {
return;
}
if (is_array($value)) {
$type = $param->getType();
if ($type == 'array') {
foreach ($value as &$item) {
$this->recursiveProcess($param->getItems(), $item);
}
} elseif ($type == 'object' && !isset($value[0])) {
// On the above line, we ensure that the array is associative and not numerically indexed
if ($properties = $param->getProperties()) {
foreach ($properties as $property) {
$name = $property->getName();
$key = $property->getWireName();
if (isset($value[$key])) {
$this->recursiveProcess($property, $value[$key]);
if ($key != $name) {
$value[$name] = $value[$key];
unset($value[$key]);
}
}
}
}
}
}
$value = $param->filter($value);
}
}
|