Browse Source

can roughly create a schema

pull/2/head
Cerys 4 months ago
parent
commit
b27ceacaa1
  1. 52
      src/SchemaBuilder/Helpers/SchemaBuilder.php

52
src/SchemaBuilder/Helpers/SchemaBuilder.php

@ -0,0 +1,52 @@
<?php
namespace Darksparrow\DeegraphPHP\SchemaBuilder\Helpers;
use Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocument;
use ReflectionClass;
class SchemaBuilder
{
public static function GenerateSchema(object $targetSchema): array
{
$reflection = new ReflectionClass($targetSchema);
$properties = $reflection->getProperties();
$attributes = $reflection->getAttributes()[0];
$schema = [];
/*
* Schema "meta-data" from here...
*/
foreach($attributes->getArguments() as $key=>$value)
{
if($value != "")
$schema["@$key"] = $value;
}
/*
* Property handling from here...
*/
foreach ($properties as $property) {
$attributes = $property->getAttributes();
$propertyName = $property->getName();
$propertySchema = [];
foreach ($attributes as $attribute)
{
if($attribute->getName() != "Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocumentField")
continue;
foreach($attribute->getArguments() as $key=>$value)
{
if($value != "")
$propertySchema["@$key"] = $value;
}
}
$schema["$propertyName"] = $propertySchema;
}
return $schema;
}
}
Loading…
Cancel
Save