/** * @param string[]|false $headers * @return string */ public static function headerToReason($headers) { if (!empty($headers)) { $parsedHeaders = \GuzzleHttp\Psr7\parse_header($headers); foreach ($parsedHeaders as $value) { if (isset($value['error'])) { return $value['error']; } } } return null; }
/** * Loads all links from a REST API response and entity object, whether from the header, response body, or any other properties available to extract useful links for this state instance. * * @return array */ protected function loadLinks() { $links = array(); //if there's a location, we'll consider it a "self" link. $myLocation = $this->response->getHeader('Location'); if (isset($myLocation[0])) { $links['self'] = new Link(); $links['self']->setRel('self'); $links['self']->setHref($myLocation[0]); } //load link headers $linkHeaders = \GuzzleHttp\Psr7\parse_header($this->response->getHeader('Link')); foreach ($linkHeaders as $linkHeader) { $linkHeader['href'] = trim($linkHeader[0], '<>'); if (isset($linkHeader['rel'])) { $link = new Link($linkHeader); $links[$linkHeader['rel']] = $link; } } //load links from the entity. if (isset($this->entity) && $this->entity->getLinks() != null) { $links = array_merge($links, $this->entity->getLinks()); } $scope = $this->getScope(); if (isset($scope) && is_object($scope)) { $links = array_merge($links, $scope->getLinks()); } return $links; }
/** * @return array */ public function getLastLinks() { return \GuzzleHttp\Psr7\parse_header($this->lastResponse->getHeader('Link')); }