diff --git a/src/SchemaBuilder/Attributes/SchemaDocument.php b/src/SchemaBuilder/Attributes/SchemaDocument.php index b49adeb..d450ef6 100644 --- a/src/SchemaBuilder/Attributes/SchemaDocument.php +++ b/src/SchemaBuilder/Attributes/SchemaDocument.php @@ -5,6 +5,7 @@ namespace Darksparrow\DeegraphPHP\SchemaBuilder\Attributes; use PhpParser\Node\Attribute; use ReflectionClass; +use PhpParser\Node\Name; #[\Attribute] class SchemaDocument extends Attribute @@ -22,6 +23,6 @@ class SchemaDocument extends Attribute $this->MaximumSize = $maxSize; $this->Comment = $comment; $this->MIMEType = $mimeType; - parent::__construct("SchemaDocument", [], []); + parent::__construct(new Name("SchemaDocument"), [], []); } } diff --git a/src/SchemaBuilder/Attributes/SchemaDocumentField.php b/src/SchemaBuilder/Attributes/SchemaDocumentField.php index c02926a..943fdd5 100644 --- a/src/SchemaBuilder/Attributes/SchemaDocumentField.php +++ b/src/SchemaBuilder/Attributes/SchemaDocumentField.php @@ -5,26 +5,30 @@ namespace Darksparrow\DeegraphPHP\SchemaBuilder\Attributes; use Darksparrow\DeegraphPHP\Enumerators\SchemaFieldExistence; use PhpParser\Node\Attribute; +use PhpParser\Node\Name; #[\Attribute] class SchemaDocumentField extends Attribute { + public string $Name; + public SchemaFieldExistence $Existence; public string $Comment; public array $ValidSchemas; public int $MaxSize; public function __construct( - SchemaFieldExistence $existence, - string $comment = "", - array $validSchemas = [], - int $maxSize = 0 + string $Name, + SchemaFieldExistence $Existence = SchemaFieldExistence::MAY, + string $Comment = "", + array $ValidSchemas = [], + int $MaxSize = 0 ) { - $this->Existence = $existence; - $this->Comment = $comment; - $this->ValidSchemas = $validSchemas; - parent::__construct("SchemaDocumentField", [], []); + $this->Existence = $Existence; + $this->Comment = $Comment; + $this->ValidSchemas = $ValidSchemas; + parent::__construct(new Name("SchemaDocumentField"), [], []); } } diff --git a/src/SchemaBuilder/Helpers/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php similarity index 60% rename from src/SchemaBuilder/Helpers/SchemaBuilder.php rename to src/SchemaBuilder/SchemaBuilder.php index a1589ce..7361904 100644 --- a/src/SchemaBuilder/Helpers/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -1,14 +1,18 @@ getProperties() as $temp) + $validAttributeNames[] = $temp->getName(); + $reflection = new ReflectionClass($targetSchema); $properties = $reflection->getProperties(); $attributes = $reflection->getAttributes()[0]; @@ -29,7 +33,7 @@ class SchemaBuilder */ foreach ($properties as $property) { $attributes = $property->getAttributes(); - $propertyName = $property->getName(); + $propertyName = ""; $propertySchema = []; foreach ($attributes as $attribute) @@ -39,10 +43,21 @@ class SchemaBuilder foreach($attribute->getArguments() as $key=>$value) { - if($value != "") - $propertySchema["@$key"] = $value; + if($key == "Name") + { + $propertyName = $value; + continue; + } + if(!in_array(needle: $key, haystack: $validAttributeNames)) + continue; + if($value == "") + continue; + + $propertySchema["@" . strtolower(preg_replace('/(?