Cerys Lewis
5 months ago
5 changed files with 103 additions and 0 deletions
@ -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, |
|||
); |
@ -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); |
@ -0,0 +1,11 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\DeegraphInteractions\Enumerators; |
|||
|
|||
enum DeegraphPermissionType: string |
|||
{ |
|||
case WRITE = "WRITE"; |
|||
case READ = "READ"; |
|||
case DELETE = "DELETE"; |
|||
case ACT = "ACT"; |
|||
} |
@ -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…
Reference in new issue