Skip to content

Commit

Permalink
Renamed "SparQL" folder to "src/"
Browse files Browse the repository at this point in the history
Minor changes in code
  • Loading branch information
byjg committed Jun 7, 2016
1 parent 029c039 commit a3dc610
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"autoload": {
"psr-4": {
"SparQL\\": "SparQL/"
"SparQL\\": "src/"
}
},
"license": "LGPL-3.0"
Expand Down
27 changes: 19 additions & 8 deletions SparQL/Connection.php → src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@ public function ns($short, $long)
$this->ns[$short] = $long;
}

/**
* @param null $params
* @return null
*/
public function cgiParams($params = null)
{
if ($params === null) {
return $this->params;
}
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)
Expand All @@ -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;
}
}
Expand All @@ -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)
{
Expand All @@ -81,7 +92,7 @@ public function dispatchQuery($sparql, $timeout = null)
$url .= "&" . $this->params;
}
if ($this->debug) {
print "<div class='debug'><a href='" . htmlspecialchars($url) . "'>" . htmlspecialchars($prefixes . $query) . "</a></div>\n";
print "<div class='debug'><a href='" . htmlspecialchars($url) . "'>" . htmlspecialchars($sparql) . "</a></div>\n";
}

$webRequest = new WebRequest($url);
Expand Down Expand Up @@ -125,7 +136,7 @@ public static function get($endpoint, $sparql, $ns = null)

$result = $db->query($sparql);
if (!$result) {
return;
return null;
}

return $result->fetchAll();
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion SparQL/ParseXml.php → src/ParseXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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');
Expand Down
7 changes: 6 additions & 1 deletion SparQL/Result.php → src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
File renamed without changes.

0 comments on commit a3dc610

Please sign in to comment.