Browse Source

can now pass in a class string, rather than an object instance

pull/1/head
Cerys Lewis 1 week ago
parent
commit
f09fd96813
  1. 2
      Examples/ExampleScripts/generateMessageSchema.php
  2. 8
      src/SchemaBuilder/SchemaBuilder.php

2
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\Examples\SchemaBuilder\Schemas\Message;
use Darksparrow\AuxiliumSchemaBuilder\SchemaBuilder\SchemaBuilder; use Darksparrow\AuxiliumSchemaBuilder\SchemaBuilder\SchemaBuilder;
SchemaBuilder::RenderSchema(new Message()); SchemaBuilder::RenderSchema(Message::class);

8
src/SchemaBuilder/SchemaBuilder.php

@ -62,11 +62,11 @@ class SchemaBuilder
/** /**
* @throws SchemaDocumentFieldNameUnsetException * @throws SchemaDocumentFieldNameUnsetException
*/ */
public static function GenerateSchema(object $targetSchema): array public static function GenerateSchema(string $targetSchemaClassName): array
{ {
$schema = []; $schema = [];
$validKeys = self::GetValidKeys(); $validKeys = self::GetValidKeys();
$reflection = new ReflectionClass($targetSchema); $reflection = new ReflectionClass(new $targetSchemaClassName());
/* /*
* Schema "meta-data" from here... * Schema "meta-data" from here...
@ -123,9 +123,9 @@ class SchemaBuilder
* @return void * @return void
* @throws SchemaDocumentFieldNameUnsetException * @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'); header('Content-Type: application/json');
echo json_encode($result, JSON_PRETTY_PRINT); echo json_encode($result, JSON_PRETTY_PRINT);
die(); die();

Loading…
Cancel
Save