diff --git a/src/Attributes/QueryBuilderQuery.php b/src/Attributes/QueryBuilderQuery.php index 766b1f3..3a558a2 100644 --- a/src/Attributes/QueryBuilderQuery.php +++ b/src/Attributes/QueryBuilderQuery.php @@ -15,32 +15,4 @@ use ReflectionClass; { parent::__construct(new Name("QueryBuilderQuery", []), [], []); } - - public function ValidateValues( - InsertQuery|PutQueryBuilder|SelectQueryBuilder $target - ): void - { - $nameBase = "Darksparrow\\DeegraphPHP\\Attributes"; - $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() == "$nameBase\\QueryBuilderRequiredField") - { - if($propertyValue == "") - throw new \Exception(); - } - - } - } - } } diff --git a/src/QueryBuilder/QueryBuilderTrait.php b/src/QueryBuilder/QueryBuilderTrait.php index 36cd465..e068db0 100755 --- a/src/QueryBuilder/QueryBuilderTrait.php +++ b/src/QueryBuilder/QueryBuilderTrait.php @@ -2,8 +2,16 @@ 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\SelectQuery\SelectQueryBuilder; +use ReflectionClass; trait QueryBuilderTrait { @@ -22,8 +30,41 @@ trait QueryBuilderTrait 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)) + 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 + |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(); + } + + } + } + } }