Browse Source

`directory` & `permission` query work

dev
Cerys 4 weeks ago
parent
commit
f23535f635
  1. 26
      src/QueryBuilder/DirectoryQuery/DirectoryQuery.php
  2. 33
      src/QueryBuilder/DirectoryQuery/DirectoryQueryBuilder.php
  3. 13
      src/QueryBuilder/DirectoryQuery/DirectoryQueryResponse.php
  4. 2
      src/QueryBuilder/PermissionsQuery/PermissionQuery.php
  5. 4
      src/QueryBuilder/PermissionsQuery/PermissionQueryBuilder.php
  6. 2
      src/QueryBuilder/PermissionsQuery/PermissionQueryBuilderInterface.php
  7. 2
      src/QueryBuilder/PermissionsQuery/PermissionQueryResponse.php

26
src/QueryBuilder/DirectoryQuery/DirectoryQuery.php

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

33
src/QueryBuilder/DirectoryQuery/DirectoryQueryBuilder.php

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

13
src/QueryBuilder/DirectoryQuery/DirectoryQueryResponse.php

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

2
src/QueryBuilder/PermissionsQuery/PermissionQuery.php

@ -4,7 +4,7 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery;
use Darksparrow\DeegraphInteractions\Core\DeegraphServer;
class PermissionQuery
final class PermissionQuery
{
protected string $QueryString;

4
src/QueryBuilder/PermissionsQuery/PermissionQueryBuilder.php

@ -7,7 +7,7 @@ use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilderTrait;
#[QueryBuilderQuery]
class PermissionQueryBuilder
final class PermissionQueryBuilder
{
use QueryBuilderTrait;
@ -35,6 +35,8 @@ class PermissionQueryBuilder
public function Build(): PermissionQuery
{
self::ValidateValues(target: $this);
$builder = "PERMISSIONS ";
if($this->On != "") $builder .= " ON {". $this->On . "}";
if($this->As != "") $builder .= " AS {". $this->As . "}";

2
src/QueryBuilder/PermissionsQuery/PermissionQueryBuilderInterface.php

@ -5,4 +5,4 @@ namespace Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery;
interface PermissionQueryBuilderInterface
{
public function Build() : PermissionQuery;
}
}

2
src/QueryBuilder/PermissionsQuery/PermissionQueryResponse.php

@ -2,7 +2,7 @@
namespace Darksparrow\DeegraphInteractions\QueryBuilder\PermissionsQuery;
class PermissionQueryResponse
final class PermissionQueryResponse
{
public bool $CanAct = false;
public bool $CanDelete = false;

Loading…
Cancel
Save