Browse Source

made a start on the GRANT query

Cerys Lewis 5 months ago
parent
commit
0a8d60c18a
  1. 11
      examples/connection.php
  2. 16
      examples/grantQuery.php
  3. 11
      src/Enumerators/DeegraphPermissionType.php
  4. 5
      src/QueryBuilder/QueryBuilder.php
  5. 60
      src/QueryBuilder/QueryBuilders/GrantQuery.php

11
examples/connection.php

@ -0,0 +1,11 @@
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Darksparrow\DeegraphInteractions\Core\DeegraphServer;
$db = new DeegraphServer(
token: "UFVUX1lPVVJfVE9LRU5fSEVSRQ==",
actor: "db36576b-cc5c-573a-8ae2-00258884d8c6",
allowSelfSignedCerts: true,
);

16
examples/grantQuery.php

@ -0,0 +1,16 @@
<?php
global $db;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../examples/connection.php';
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphPermissionType;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilder;
$grantQuery = QueryBuilder::Grant()
->GrantAll()
// ->Permissions(permissionTypes: [DeegraphPermissionType::READ])
->To(uuid: $db->GetActor());
$result = $db->RunQuery($grantQuery);
var_dump($result);

11
src/Enumerators/DeegraphPermissionType.php

@ -0,0 +1,11 @@
<?php
namespace Darksparrow\DeegraphInteractions\Enumerators;
enum DeegraphPermissionType: string
{
case WRITE = "WRITE";
case READ = "READ";
case DELETE = "DELETE";
case ACT = "ACT";
}

5
src/QueryBuilder/QueryBuilder.php

@ -2,12 +2,17 @@
namespace Darksparrow\DeegraphInteractions\QueryBuilder; namespace Darksparrow\DeegraphInteractions\QueryBuilder;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\GrantQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\InsertQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\InsertQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\PutQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\PutQuery;
use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\SelectQuery; use Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders\SelectQuery;
final class QueryBuilder final class QueryBuilder
{ {
public static function Grant(): GrantQuery
{
return new GrantQuery();
}
public static function Insert(): InsertQuery public static function Insert(): InsertQuery
{ {
return new InsertQuery(); return new InsertQuery();

60
src/QueryBuilder/QueryBuilders/GrantQuery.php

@ -0,0 +1,60 @@
<?php
namespace Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphPermissionType;
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderRequiredFieldIsNotSetException;
#[QueryBuilderQuery]
class GrantQuery
{
#[QueryBuilderRequiredField]
protected array $PermissionTypes;
#[QueryBuilderRequiredField]
protected string $GrantTo;
protected string $GrantOn = "";
protected string $GrantWhere = "";
protected bool $GrantDelegatable = false;
/**
* @throws QueryBuilderRequiredFieldIsNotSetException
*/
public function __toString(): string
{
$builder = "GRANT ";
if(sizeof($this->PermissionTypes)) $builder .= implode(separator: ",", array: $this->PermissionTypes);
if($this->GrantTo != "") $builder .= " TO $this->GrantTo";
if($this->GrantOn != "") $builder .= " ON $this->GrantOn";
if($this->GrantWhere != "") $builder .= " WHERE $this->GrantWhere";
return $builder;
}
public function Permissions(array $permissionTypes): GrantQuery
{
$this->PermissionTypes = [];
foreach($permissionTypes as $permissionType)
$this->PermissionTypes[] = $permissionType->value;
return $this;
}
public function GrantAll(): GrantQuery
{
$this->PermissionTypes = [
DeegraphPermissionType::WRITE->value,
DeegraphPermissionType::READ->value,
DeegraphPermissionType::DELETE->value,
DeegraphPermissionType::ACT->value,
];
return $this;
}
public function To(string $uuid): GrantQuery
{
$this->GrantTo = "{" . $uuid . "}";
return $this;
}
}
Loading…
Cancel
Save