From 4c76b11a67b6dfb7199360636c030d61cedcfcc1 Mon Sep 17 00:00:00 2001 From: Dave Longley Date: Mon, 29 Oct 2012 09:57:24 -0400 Subject: [PATCH] Make default url resolver a separate function. --- jsonld.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/jsonld.php b/jsonld.php index b6ceabc..000f338 100644 --- a/jsonld.php +++ b/jsonld.php @@ -172,19 +172,31 @@ function jsonld_resolve_url($url) { } // default JSON-LD GET implementation + return jsonld_default_resolve_url($url); +} + +/** + * The default implementation to retrieve JSON-LD at the given URL. + * + * @param string $url the URL to to resolve. + * + * @return the JSON-LD. + */ +function jsonld_default_resolve_url($url) { + // default JSON-LD GET implementation $opts = array('http' => - array( - 'method' => "GET", - 'header' => - "Accept: application/ld+json\r\n" . - "User-Agent: PaySwarm PHP Client/1.0\r\n")); + array( + 'method' => "GET", + 'header' => + "Accept: application/ld+json\r\n" . + "User-Agent: PaySwarm PHP Client/1.0\r\n")); $stream = stream_context_create($opts); $result = @file_get_contents($url, false, $stream); if($result === false) { throw new Exception("Could not GET url: '$url'"); } return $result; -} +} /** Registered global RDF Statement parsers hashed by content-type. */ global $jsonld_rdf_parsers;