From f09fd96813f73c740565c9b575057ba27c42ad8b Mon Sep 17 00:00:00 2001 From: Cerys Lewis Date: Tue, 12 Nov 2024 16:04:05 +0000 Subject: [PATCH] can now pass in a class string, rather than an object instance --- Examples/ExampleScripts/generateMessageSchema.php | 2 +- src/SchemaBuilder/SchemaBuilder.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/ExampleScripts/generateMessageSchema.php b/Examples/ExampleScripts/generateMessageSchema.php index 5ce2279..26eef41 100644 --- a/Examples/ExampleScripts/generateMessageSchema.php +++ b/Examples/ExampleScripts/generateMessageSchema.php @@ -9,4 +9,4 @@ require_once __DIR__ . "/../../Examples/Schemas/Message.php"; use Darksparrow\AuxiliumSchemaBuilder\Examples\SchemaBuilder\Schemas\Message; use Darksparrow\AuxiliumSchemaBuilder\SchemaBuilder\SchemaBuilder; -SchemaBuilder::RenderSchema(new Message()); +SchemaBuilder::RenderSchema(Message::class); diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index dac19d8..6da8816 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -62,11 +62,11 @@ class SchemaBuilder /** * @throws SchemaDocumentFieldNameUnsetException */ - public static function GenerateSchema(object $targetSchema): array + public static function GenerateSchema(string $targetSchemaClassName): array { $schema = []; $validKeys = self::GetValidKeys(); - $reflection = new ReflectionClass($targetSchema); + $reflection = new ReflectionClass(new $targetSchemaClassName()); /* * Schema "meta-data" from here... @@ -123,9 +123,9 @@ class SchemaBuilder * @return void * @throws SchemaDocumentFieldNameUnsetException */ - #[NoReturn] public static function RenderSchema(object $targetSchema): void + #[NoReturn] public static function RenderSchema(string $targetSchemaClassName): void { - $result = self::GenerateSchema(new $targetSchema()); + $result = self::GenerateSchema($targetSchemaClassName); header('Content-Type: application/json'); echo json_encode($result, JSON_PRETTY_PRINT); die();