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.

46 lines
1.4 KiB

<?php
namespace Darksparrow\DeegraphPHP\Attributes;
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\InsertQuery;
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\PutQuery;
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\SelectQuery;
use PhpParser\Node\Attribute;
use PhpParser\Node\Name;
use ReflectionClass;
#[\Attribute] class QueryBuilderQuery extends Attribute
{
public function __construct()
{
parent::__construct(new Name("QueryBuilderQuery", []), [], []);
}
public function ValidateValues(
InsertQuery|PutQuery|SelectQuery $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();
}
}
}
}
}