3 * @todo Add file header and documentation.
12 function __construct($str)
14 preg_match('/^<[^>]+>/', $str, $uri_reference);
15 //if (empty($uri_reference)) return;
17 $this->href = trim($uri_reference[0], '<>');
21 // remove uri-reference from header
22 $str = substr($str, strlen($uri_reference[0]));
25 $params = explode(';', $str);
27 foreach ($params as $param) {
28 if (empty($param)) continue;
29 list($param_name, $param_value) = explode('=', $param, 2);
30 $param_name = trim($param_name);
31 $param_value = preg_replace('(^"|"$)', '', trim($param_value));
33 // for now we only care about 'rel' and 'type' link params
34 // TODO do something with the other links-params
35 switch ($param_name) {
37 $this->rel = trim($param_value);
41 $this->type = trim($param_value);
46 static function getLink($response, $rel=null, $type=null)
48 $headers = $response->getHeader('Link');
50 // Can get an array or string, so try to simplify the path
51 if (!is_array($headers)) {
52 $headers = array($headers);
55 foreach ($headers as $header) {
56 $lh = new LinkHeader($header);
58 if ((is_null($rel) || $lh->rel == $rel) &&
59 (is_null($type) || $lh->type == $type)) {