diff --git a/composer.json b/composer.json index bdb2a87..03020a0 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ }, "autoload": { "psr-4": { - "SparQL\\": "SparQL/" + "SparQL\\": "src/" } }, "license": "LGPL-3.0" diff --git a/SparQL/Connection.php b/src/Connection.php similarity index 94% rename from SparQL/Connection.php rename to src/Connection.php index 15bd477..dac21c1 100644 --- a/SparQL/Connection.php +++ b/src/Connection.php @@ -26,6 +26,10 @@ public function ns($short, $long) $this->ns[$short] = $long; } + /** + * @param null $params + * @return null + */ public function cgiParams($params = null) { if ($params === null) { @@ -33,15 +37,17 @@ public function cgiParams($params = null) } if ($params === "") { $this->params = null; - return; + return null; } $this->params = $params; + + return $this->params; } /** * - * @param type $query - * @param type $timeout + * @param string $query + * @param int|null $timeout * @return Result */ public function query($query, $timeout = null) @@ -57,12 +63,16 @@ public function query($query, $timeout = null) return new Result($parser->rows, $parser->fields); } - public function alive($timeout = 3) + /** + * @param int $timeout + * @return bool + */ + public function alive($timeout = 3000) { try { $this->query("SELECT * WHERE { ?s ?p ?o } LIMIT 1", $timeout); return true; - } catch (Exception $ex) { + } catch (\Exception $ex) { return false; } } @@ -72,7 +82,8 @@ public function alive($timeout = 3) * @param string $sparql * @param int $timeout Timeout in mileseconds * @return string - * @throws Exception + * @throws ConnectionException + * @throws \SparQL\Exception */ public function dispatchQuery($sparql, $timeout = null) { @@ -81,7 +92,7 @@ public function dispatchQuery($sparql, $timeout = null) $url .= "&" . $this->params; } if ($this->debug) { - print "
\n"; + print "\n"; } $webRequest = new WebRequest($url); @@ -125,7 +136,7 @@ public static function get($endpoint, $sparql, $ns = null) $result = $db->query($sparql); if (!$result) { - return; + return null; } return $result->fetchAll(); diff --git a/SparQL/ConnectionException.php b/src/ConnectionException.php similarity index 100% rename from SparQL/ConnectionException.php rename to src/ConnectionException.php diff --git a/SparQL/Exception.php b/src/Exception.php similarity index 100% rename from SparQL/Exception.php rename to src/Exception.php diff --git a/SparQL/ParseXml.php b/src/ParseXml.php similarity index 97% rename from SparQL/ParseXml.php rename to src/ParseXml.php index 264fad7..f5a2413 100644 --- a/SparQL/ParseXml.php +++ b/src/ParseXml.php @@ -25,6 +25,12 @@ class ParseXml // either you pass url atau contents. // Use 'url' or 'contents' for the parameter protected $type; + + protected $result; + protected $part; + protected $part_type; + protected $part_datatype; + protected $part_lang; // public function with the default parameter value public function __construct($url) @@ -50,7 +56,6 @@ protected function parse() { $this->rows = array(); $this->fields = array(); - $data = ''; $this->parser = xml_parser_create("UTF-8"); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'startXml', 'endXml'); diff --git a/SparQL/Result.php b/src/Result.php similarity index 93% rename from SparQL/Result.php rename to src/Result.php index e0f09b4..1d85381 100644 --- a/SparQL/Result.php +++ b/src/Result.php @@ -22,10 +22,15 @@ public function __construct($rows, $fields) $this->fields = $fields; } + /** + * Fetch as array + * + * @return array|null + */ public function fetchArray() { if (!isset($this->rows[$this->i])) { - return; + return null; } $result = array(); diff --git a/SparQL/Results.php b/src/Results.php similarity index 100% rename from SparQL/Results.php rename to src/Results.php