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:
<?php
namespace Guzzle\Service\Command\LocationVisitor\Response;
use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;
class HeaderVisitor extends AbstractResponseVisitor
{
public function visit(
CommandInterface $command,
Response $response,
Parameter $param,
&$value,
$context = null
) {
if ($param->getType() == 'object' && $param->getAdditionalProperties() instanceof Parameter) {
$this->processPrefixedHeaders($response, $param, $value);
} else {
$value[$param->getName()] = $param->filter((string) $response->getHeader($param->getWireName()));
}
}
protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
{
if ($prefix = $param->getSentAs()) {
$container = $param->getName();
$len = strlen($prefix);
foreach ($response->getHeaders()->toArray() as $key => $header) {
if (stripos($key, $prefix) === 0) {
$value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
}
}
}
}
}