Compare commits

...

2 Commits

  1. 4
      composer.json
  2. 21
      src/Core/DeegraphServer.php
  3. 32
      src/DataStructures/KeyValuePair.php
  4. 28
      src/DataStructures/QueryResponseRow.php
  5. 17
      src/DataStructures/QueryResponseWrapper.php
  6. 3
      src/QueryBuilder/QueryBuilder.php
  7. 5
      src/QueryBuilder/QueryBuilders/SelectQuery.php

4
composer.json

@ -22,10 +22,10 @@
},
"require": {
"php": ">=8.1",
"ext-curl": "*",
"phpunit/phpunit": "^9.5"
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"scripts": {
"test": "phpunit"

21
src/Core/DeegraphServer.php

@ -1,6 +1,6 @@
<?php
namespace Darksparrow\DeegraphPHP\Core;
namespace Darksparrow\DeegraphInteractions\Core;
use Darksparrow\DeegraphInteractions\DataStructures\QueryResponseWrapper;
use Darksparrow\DeegraphInteractions\DataStructures\ServerInfo;
@ -10,10 +10,12 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\SelectQuery;
class DeegraphServer
{
private string $ServerDomain;
private int $Port;
private string $Token;
private string $Actor;
private string $ServerDomain;
private int $Port;
private bool $AllowSelfSignedCerts;
public function __construct(
@ -23,10 +25,11 @@ class DeegraphServer
int $port = 8088,
bool $allowSelfSignedCerts = false)
{
$this->ServerDomain = $server;
$this->Port = $port;
$this->Token = $token;
$this->Actor = $actor;
$this->ServerDomain = $server;
$this->Port = $port;
$this->AllowSelfSignedCerts = $allowSelfSignedCerts;
}
@ -65,8 +68,14 @@ class DeegraphServer
}
}
$result = curl_exec($ch);
if(curl_error($ch) == "SSL certificate problem: unable to get local issuer certificate")
{
throw new \Exception();
die();
}
curl_close($ch);
return $result;

32
src/DataStructures/KeyValuePair.php

@ -0,0 +1,32 @@
<?php
namespace Darksparrow\DeegraphInteractions\DataStructures;
class KeyValuePair
{
public string $Key;
public ?string $Value;
public function __construct(string $key, ?string $value)
{
$this->Key = $key;
$this->Value = $value;
}
public function __toString(): string
{
if(isset($this->Key) && isset($this->Value))
return "{$this->Key} => \"{$this->Value}\"";
if(!isset($this->Key) && isset($this->Value))
return "NULL => \"{$this->Value}\"";
if(isset($this->Key) && !isset($this->Value))
return "{$this->Key} => NULL";
if(isset($this->Key) && isset($this->Value))
return "NULL => NULL";
return "FAIL";
}
}

28
src/DataStructures/QueryResponseRow.php

@ -0,0 +1,28 @@
<?php
namespace Darksparrow\DeegraphInteractions\DataStructures;
class QueryResponseRow
{
public string $Search;
public array $Results;
public static function FromArray(array $array): QueryResponseRow
{
$builder = new QueryResponseRow();
$builder->Search = key(array: $array);
foreach($array["{$builder->Search}"] as $key=>$value)
{
$builder->Results[] = new KeyValuePair(key: $key, value: $value);
}
return $builder;
}
public function __toString(): string
{
return json_encode($this, JSON_PRETTY_PRINT);
}
}

17
src/DataStructures/QueryResponseWrapper.php

@ -13,9 +13,24 @@ class QueryResponseWrapper
$builder = new QueryResponseWrapper();
$builder->Rows = $temp["@rows"];
foreach($temp["@rows"] as $row) $builder->Rows[] = QueryResponseRow::FromArray(array: $row);
$builder->RowFormat = $temp["@row_format"];
return $builder;
}
public function Flatten(): array
{
$builder = [];
foreach($this->Rows as $row)
{
foreach($row->Results as $result)
{
$builder[] = $result;
}
}
return $builder;
}
}

3
src/QueryBuilder/QueryBuilder.php

@ -6,9 +6,8 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\PutQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\SelectQuery;
class QueryBuilder
final class QueryBuilder
{
public static function Insert(): InsertQuery
{
return new InsertQuery();

5
src/QueryBuilder/QueryBuilders/SelectQuery.php

@ -38,6 +38,11 @@ final class SelectQuery
return $builder;
}
public function RelativePath(string $relativePath): SelectQuery
{
$this->RelativePaths = [$relativePath];
return $this;
}
public function RelativePaths(array $relativePaths): SelectQuery
{
$this->RelativePaths = $relativePaths;

Loading…
Cancel
Save