9 function __construct($str)
11 preg_match('/^<[^>]+>/', $str, $uri_reference);
12 //if (empty($uri_reference)) return;
14 $this->href = trim($uri_reference[0], '<>');
18 // remove uri-reference from header
19 $str = substr($str, strlen($uri_reference[0]));
22 $params = explode(';', $str);
24 foreach ($params as $param) {
25 if (empty($param)) continue;
26 list($param_name, $param_value) = explode('=', $param, 2);
27 $param_name = trim($param_name);
28 $param_value = preg_replace('(^"|"$)', '', trim($param_value));
30 // for now we only care about 'rel' and 'type' link params
31 // TODO do something with the other links-params
32 switch ($param_name) {
34 $this->rel = trim($param_value);
38 $this->type = trim($param_value);
43 static function getLink($response, $rel=null, $type=null)
45 $headers = $response->getHeader('Link');
47 // Can get an array or string, so try to simplify the path
48 if (!is_array($headers)) {
49 $headers = array($headers);
52 foreach ($headers as $header) {
53 $lh = new LinkHeader($header);
55 if ((is_null($rel) || $lh->rel == $rel) &&
56 (is_null($type) || $lh->type == $type)) {