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.
47 lines
1.3 KiB
47 lines
1.3 KiB
7 months ago
|
<?php
|
||
|
|
||
|
namespace Darksparrow\DeegraphPHP\Attributes;
|
||
|
|
||
|
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\Insert;
|
||
|
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\Put;
|
||
|
use Darksparrow\DeegraphPHP\QueryBuilder\QueryBuilders\Select;
|
||
|
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(
|
||
|
Insert|Put|Select $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();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|