/** * Add a prefixed array of headers to the request * * @param RequestInterface $request Request to update * @param Parameter $param Parameter object * @param array $value Header array to add * * @throws InvalidArgumentException */ protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value) { if (!is_array($value)) { throw new InvalidArgumentException('An array of mapped headers expected, but received a single value'); } $prefix = $param->getSentAs(); foreach ($value as $headerName => $headerValue) { $request->setHeader($prefix . $headerName, $headerValue); } }
/** * Process a prefixed header array * * @param Response $response Response that contains the headers * @param Parameter $param Parameter object * @param array $value Value response array to modify */ protected function processPrefixedHeaders(Response $response, Parameter $param, &$value) { // Grab prefixed headers that should be placed into an array with the prefix stripped if ($prefix = $param->getSentAs()) { $container = $param->getName(); $len = strlen($prefix); // Find all matching headers and place them into the containing element foreach ($response->getHeaders()->toArray() as $key => $header) { if (stripos($key, $prefix) === 0) { // Account for multi-value headers $value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header; } } } }