You are here

public static function HttpHelpers::parseLinkRelation in Feeds 8.3

Finds a hub link from a Link header.

Parameters

string $link_header: The full link header string.

string $relation: The relationship to find.

Return value

string The link, or an empty string if one wasn't found.

1 call to HttpHelpers::parseLinkRelation()
HttpHelpers::findLinkHeader in src/Component/HttpHelpers.php
Finds a relation type in a header array.

File

src/Component/HttpHelpers.php, line 52

Class

HttpHelpers
Various helpers for dealing with HTTP data.

Namespace

Drupal\feeds\Component

Code

public static function parseLinkRelation($link_header, $relation) {
  if (!preg_match_all('/<([^>]*)>\\s*;.*?rel\\s*=(.+?)(?:;|$)/is', trim($link_header), $matches)) {
    return '';
  }
  foreach ($matches[2] as $delta => $match) {
    $match = trim($match);

    // Strip quotes if present.
    $len = strlen($match);
    if ($match[0] === '"' && $match[$len - 1] === '"') {
      $match = substr($match, 1, $len - 2);
    }

    // Normalize whitespace.
    preg_replace('/\\s+/s', ' ', trim($match));
    if (in_array($relation, explode(' ', $match), TRUE)) {
      return $matches[1][$delta];
    }
  }
  return '';
}