1 changed files with 52 additions and 0 deletions
			
			
		| @ -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…
					
					
				
		Reference in new issue