Browse Source

code for the REFERENCES request

dev
Cerys 4 weeks ago
parent
commit
7e3da11f72
  1. 21
      examples/QueryExample_References.php
  2. 5
      src/QueryBuilder/QueryBuilder.php
  3. 2
      src/QueryBuilder/QueryBuilderTrait.php
  4. 26
      src/QueryBuilder/ReferencesQuery/ReferencesQuery.php
  5. 35
      src/QueryBuilder/ReferencesQuery/ReferencesQueryBuilder.php
  6. 13
      src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php

21
examples/QueryExample_References.php

@ -0,0 +1,21 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../examples/DeegraphConnection.php';
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder;
$result = QueryBuilder::References()
->RelativePath("{0b368d41-7c15-42c8-899c-2b178ae9d983}")
->Build()
->RunQuery(DeegraphConnection::DB())
;
echo "References\n";
echo "=========\n";
foreach($result->Map as $key=>$value)
{
echo str_pad($key, 20) . ": " . $value . "\n";
}

5
src/QueryBuilder/QueryBuilder.php

@ -6,6 +6,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryB
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder;
final class QueryBuilder
@ -30,4 +31,8 @@ final class QueryBuilder
{
return new DirectoryQueryBuilder();
}
public static function References(): ReferencesQueryBuilder
{
return new ReferencesQueryBuilder();
}
}

2
src/QueryBuilder/QueryBuilderTrait.php

@ -10,6 +10,7 @@ use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\InsertQuery\InsertQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\PutQuery\PutQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery\ReferencesQueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\SelectQuery\SelectQueryBuilder;
use ReflectionClass;
@ -41,6 +42,7 @@ trait QueryBuilderTrait
|InsertQueryBuilder
|PermissionQueryBuilder
|PutQueryBuilder
|ReferencesQueryBuilder
|SelectQueryBuilder
$target
): void

26
src/QueryBuilder/ReferencesQuery/ReferencesQuery.php

@ -0,0 +1,26 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery;
use Darksparrow\DeegraphInteractions\Core\DeegraphServer;
final class ReferencesQuery
{
protected string $QueryString;
public function __construct(string $queryString)
{
$this->QueryString = $queryString;
}
public function RunQuery(DeegraphServer $server): ReferencesQueryResponse
{
$response = $server->RunRawRequest(
endpoint: "/api/v1/@query",
method: "POST",
body: $this->QueryString
);
$temp = json_decode($response, true);
return new ReferencesQueryResponse($temp);
}
}

35
src/QueryBuilder/ReferencesQuery/ReferencesQueryBuilder.php

@ -0,0 +1,35 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery\PermissionQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
final class ReferencesQueryBuilder
{
use QueryBuilderTrait;
#[QueryBuilderRequiredField]
protected string $RelativePath = "";
public function RelativePath(string $relativePath): ReferencesQueryBuilder
{
self::ValidateDeegraphPath(target: $relativePath);
$this->RelativePath = $relativePath;
return $this;
}
public function Build(): ReferencesQuery
{
self::ValidateValues(target: $this);
$builder = "REFERENCES " . $this->RelativePath;
return new ReferencesQuery(queryString: $builder);
}
}

13
src/QueryBuilder/ReferencesQuery/ReferencesQueryResponse.php

@ -0,0 +1,13 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\ReferencesQuery;
class ReferencesQueryResponse
{
public array $Map;
public function __construct(array $deegraphResponse)
{
$this->Map = $deegraphResponse["@map"];
}
}
Loading…
Cancel
Save