You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.2 KiB
67 lines
2.2 KiB
<?php
|
|
|
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder\QueryBuilders;
|
|
|
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderQuery;
|
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
|
|
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphEqualityOperator;
|
|
use Darksparrow\DeegraphInteractions\Enumerators\DeegraphPermissionType;
|
|
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderRequiredFieldIsNotSetException;
|
|
use Darksparrow\DeegraphInteractions\Interfaces\QueryBuilderInterface;
|
|
use Darksparrow\DeegraphInteractions\QueryInstance\GrantQuery;
|
|
|
|
#[QueryBuilderQuery]
|
|
final class GrantQueryBuilder implements QueryBuilderInterface
|
|
{
|
|
#[QueryBuilderRequiredField]
|
|
protected array $PermissionTypes;
|
|
|
|
protected string $GrantOn = "";
|
|
protected string $GrantWhere = "";
|
|
protected bool $GrantDelegatable = false;
|
|
|
|
|
|
/**
|
|
* @throws QueryBuilderRequiredFieldIsNotSetException
|
|
*/
|
|
public function Build(): GrantQuery
|
|
{
|
|
$builder = "GRANT ";
|
|
if(sizeof($this->PermissionTypes)) $builder .= implode(separator: ",", array: $this->PermissionTypes);
|
|
if($this->GrantOn != "") $builder .= " ON $this->GrantOn";
|
|
if($this->GrantWhere != "") $builder .= " WHERE $this->GrantWhere";
|
|
|
|
return new GrantQuery(queryString: $builder);
|
|
}
|
|
|
|
public function Permissions(array $permissionTypes): GrantQueryBuilder
|
|
{
|
|
$this->PermissionTypes = [];
|
|
foreach($permissionTypes as $permissionType)
|
|
$this->PermissionTypes[] = $permissionType->value;
|
|
return $this;
|
|
}
|
|
|
|
public function GrantAll(): GrantQueryBuilder
|
|
{
|
|
$this->PermissionTypes = [
|
|
DeegraphPermissionType::WRITE->value,
|
|
DeegraphPermissionType::READ->value,
|
|
DeegraphPermissionType::DELETE->value,
|
|
DeegraphPermissionType::ACT->value,
|
|
];
|
|
return $this;
|
|
}
|
|
|
|
public function On(string $target): GrantQueryBuilder
|
|
{
|
|
$this->GrantOn = $target;
|
|
return $this;
|
|
}
|
|
|
|
public function Where(string $target, DeegraphEqualityOperator $operator, string $value): GrantQueryBuilder
|
|
{
|
|
$this->GrantWhere = "$target $operator->value $value";
|
|
return $this;
|
|
}
|
|
}
|
|
|