|
@ -1,14 +1,18 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
namespace Darksparrow\DeegraphPHP\SchemaBuilder\Helpers; |
|
|
namespace Darksparrow\DeegraphPHP\SchemaBuilder; |
|
|
|
|
|
|
|
|
use Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocument; |
|
|
use Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocumentField; |
|
|
use ReflectionClass; |
|
|
use ReflectionClass; |
|
|
|
|
|
|
|
|
class SchemaBuilder |
|
|
class SchemaBuilder |
|
|
{ |
|
|
{ |
|
|
public static function GenerateSchema(object $targetSchema): array |
|
|
public static function GenerateSchema(object $targetSchema): array |
|
|
{ |
|
|
{ |
|
|
|
|
|
$validAttributeNames = []; |
|
|
|
|
|
foreach((new ReflectionClass(new SchemaDocumentField("EMPTY")))->getProperties() as $temp) |
|
|
|
|
|
$validAttributeNames[] = $temp->getName(); |
|
|
|
|
|
|
|
|
$reflection = new ReflectionClass($targetSchema); |
|
|
$reflection = new ReflectionClass($targetSchema); |
|
|
$properties = $reflection->getProperties(); |
|
|
$properties = $reflection->getProperties(); |
|
|
$attributes = $reflection->getAttributes()[0]; |
|
|
$attributes = $reflection->getAttributes()[0]; |
|
@ -29,7 +33,7 @@ class SchemaBuilder |
|
|
*/ |
|
|
*/ |
|
|
foreach ($properties as $property) { |
|
|
foreach ($properties as $property) { |
|
|
$attributes = $property->getAttributes(); |
|
|
$attributes = $property->getAttributes(); |
|
|
$propertyName = $property->getName(); |
|
|
$propertyName = ""; |
|
|
$propertySchema = []; |
|
|
$propertySchema = []; |
|
|
|
|
|
|
|
|
foreach ($attributes as $attribute) |
|
|
foreach ($attributes as $attribute) |
|
@ -39,10 +43,21 @@ class SchemaBuilder |
|
|
|
|
|
|
|
|
foreach($attribute->getArguments() as $key=>$value) |
|
|
foreach($attribute->getArguments() as $key=>$value) |
|
|
{ |
|
|
{ |
|
|
if($value != "") |
|
|
if($key == "Name") |
|
|
$propertySchema["@$key"] = $value; |
|
|
{ |
|
|
|
|
|
$propertyName = $value; |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if(!in_array(needle: $key, haystack: $validAttributeNames)) |
|
|
|
|
|
continue; |
|
|
|
|
|
if($value == "") |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
$propertySchema["@" . strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $key))] = $value; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
if($propertyName == "") |
|
|
|
|
|
throw new \Exception(); |
|
|
|
|
|
|
|
|
$schema["$propertyName"] = $propertySchema; |
|
|
$schema["$propertyName"] = $propertySchema; |
|
|
} |
|
|
} |