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.
72 lines
2.8 KiB
72 lines
2.8 KiB
<?php
|
|
|
|
namespace Darksparrow\DeegraphInteractions\QueryBuilder;
|
|
|
|
use Darksparrow\DeegraphInteractions\Attributes\QueryBuilderRequiredField;
|
|
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderConflictingFieldAlreadyExistsException;
|
|
use Darksparrow\DeegraphInteractions\Exceptions\QueryBuilderInvalidInputException;
|
|
use Darksparrow\DeegraphInteractions\QueryBuilder\DirectoryQuery\DirectoryQueryBuilder;
|
|
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;
|
|
|
|
trait QueryBuilderTrait
|
|
{
|
|
protected function RegexValidate(string $target, string $pattern): string
|
|
{
|
|
if (!preg_match(pattern: $pattern, subject: $target))
|
|
throw new QueryBuilderInvalidInputException();
|
|
return $target;
|
|
}
|
|
|
|
protected function EnsureNotSet(string $target): void
|
|
{
|
|
if ($target != "")
|
|
throw new QueryBuilderConflictingFieldAlreadyExistsException();
|
|
}
|
|
|
|
protected function ValidateDeegraphPath(string $target): string
|
|
{
|
|
if (!preg_match(pattern: "/(^(\{[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\})$)|(^\{[0-9a-f]{8}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{4}\b-[0-9a-f]{12}\}(\/([a-z][a-z0-9]*|[0-9]+|#|\*))+$)|(^(([a-z][a-z0-9]*|[0-9]+|#|\*))(\/([a-z][a-z0-9]*|[0-9]+|#|\*))*$)/", subject: $target))
|
|
throw new QueryBuilderInvalidInputException();
|
|
return $target;
|
|
}
|
|
|
|
|
|
public function ValidateValues(
|
|
DirectoryQueryBuilder
|
|
|InsertQueryBuilder
|
|
|PermissionQueryBuilder
|
|
|PutQueryBuilder
|
|
|ReferencesQueryBuilder
|
|
|SelectQueryBuilder
|
|
$target
|
|
): void
|
|
{
|
|
$reflection = new ReflectionClass($target);
|
|
$properties = $reflection->getProperties();
|
|
|
|
foreach ($properties as $property)
|
|
{
|
|
$attributes = $property->getAttributes();
|
|
$propertyName = $property->getName();
|
|
$propertyValue = $property->getValue($target);
|
|
|
|
if(sizeof($attributes) == 0) continue;
|
|
|
|
foreach ($attributes as $attribute)
|
|
{
|
|
if($attribute->getName() == QueryBuilderRequiredField::class)
|
|
{
|
|
if($propertyValue == "")
|
|
throw new \Exception();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|