private function parseContextLinkHeaders(array $values, IRI $baseIri)
    {
        // Separate multiple links contained in a single header value
        for ($i = 0, $total = count($values); $i < $total; $i++) {
            if (strpos($values[$i], ',') !== false) {
                foreach (preg_split('/,(?=([^"]*"[^"]*")*[^"]*$)/', $values[$i]) as $v) {
                    $values[] = trim($v);
                }
                unset($values[$i]);
            }
        }

        $contexts = $matches = array();
        $trimWhitespaceCallback = function ($str) {
            return trim($str, "\"'  \n\t");
        };

        // Split the header in key-value pairs
        foreach ($values as $val) {
            $part = array();
            foreach (preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) as $kvp) {
                preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches);
                $pieces = array_map($trimWhitespaceCallback, $matches[0]);
                $part[$pieces[0]] = isset($pieces[1]) ? $pieces[1] : '';
            }

            if (in_array('http://www.w3.org/ns/json-ld#context', explode(' ', $part['rel']))) {
                $contexts[] = (string) $baseIri->resolve(trim(key($part), '<> '));
            }
        }

        return array_values(array_unique($contexts));
    }
private function parseContextLinkHeaders(array $values, IRI $baseIri)
    {
        // Separate multiple links contained in a single header value
        for ($i = 0, $total = count($values); $i < $total; $i++) {
            if (strpos($values[$i], ',') !== false) {
                foreach (preg_split('/,(?=([^"]*"[^"]*")*[^"]*$)/', $values[$i]) as $v) {
                    $values[] = trim($v);
                }
                unset($values[$i]);
            }
        }

        $contexts = $matches = array();
        $trimWhitespaceCallback = function ($str) {
            return trim($str, "\"'  \n\t");
        };

        // Split the header in key-value pairs
        foreach ($values as $val) {
            $part = array();
            foreach (preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) as $kvp) {
                preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches);
                $pieces = array_map($trimWhitespaceCallback, $matches[0]);
                $part[$pieces[0]] = isset($pieces[1]) ? $pieces[1] : '';
            }

            if (in_array('http://www.w3.org/ns/json-ld#context', explode(' ', $part['rel']))) {
                $contexts[] = (string) $baseIri->resolve(trim(key($part), '<> '));
            }
        }

        return array_values(array_unique($contexts));
    }
private function parseContextLinkHeaders ( array $ values , IRI $ baseIri ) { // Separate multiple links contained in a single header value for ( $ i = 0 , $ total = count ( $ values ) ; $ i < $ total ; $ i ++ ) { if ( strpos ( $ values [ $ i ] , ',' ) !== false ) { foreach ( preg_split ( '/,(?=([^"]*"[^"]*")*[^"]*$)/' , $ values [ $ i ] ) as $ v ) { $ values [ ] = trim ( $ v ) ; } unset ( $ values [ $ i ] ) ; } } $ contexts = $ matches = array ( ) ; $ trimWhitespaceCallback = function ( $ str ) { return trim ( $ str , "\"'  \n\t" ) ; } ; // Split the header in key-value pairs foreach ( $ values as $ val ) { $ part = array ( ) ; foreach ( preg_split ( '/;(?=([^"]*"[^"]*")*[^"]*$)/' , $ val ) as $ kvp ) { preg_match_all ( '/<[^>]+>|[^=]+/' , $ kvp , $ matches ) ; $ pieces = array_map ( $ trimWhitespaceCallback , $ matches [ 0 ] ) ; $ part [ $ pieces [ 0 ] ] = isset ( $ pieces [ 1 ] ) ? $ pieces [ 1 ] : '' ; } if ( in_array ( 'http://www.w3.org/ns/json-ld#context' , explode ( ' ' , $ part [ 'rel' ] ) ) ) { $ contexts [ ] = ( string ) $ baseIri -> resolve ( trim ( key ( $ part ) , '<> ' ) ) ; } } return array_values ( array_unique ( $ contexts ) ) ; }
Parse HTTP Link headers

@param array $values  An array of HTTP Link header values
@param  IRI  $baseIri The document's URL (used to expand relative URLs to absolutes)

@return array An array of parsed HTTP Link headers
Parse HTTP Link headers