From fb9d556547441ee6b4ad426578cf78d3155a0120 Mon Sep 17 00:00:00 2001 From: Cerys Date: Fri, 7 Jun 2024 16:04:21 +0100 Subject: [PATCH 01/13] the reflection stuff requires `phpunit/phpunit` --- composer.json | 4 ++-- composer.lock | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index a6908ee..783481f 100755 --- a/composer.json +++ b/composer.json @@ -22,10 +22,10 @@ }, "require": { "php": ">=8.1", - "ext-curl": "*" + "ext-curl": "*", + "phpunit/phpunit": "^9.5" }, "require-dev": { - "phpunit/phpunit": "^9.5" }, "scripts": { "test": "phpunit" diff --git a/composer.lock b/composer.lock index a3fddfa..63efa75 100755 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "41893d70ec149c7be1cf37242a2b8336", - "packages": [], - "packages-dev": [ + "content-hash": "50a1b1c6fce1e9a0010b700a3f1f5662", + "packages": [ { "name": "doctrine/instantiator", "version": "2.0.x-dev", @@ -1754,6 +1753,7 @@ "time": "2024-03-03T12:36:25+00:00" } ], + "packages-dev": [], "aliases": [], "minimum-stability": "dev", "stability-flags": [], From 76cf239d88f11d2131a3ec579daa4d5ecd0bd1dd Mon Sep 17 00:00:00 2001 From: Cerys Date: Fri, 7 Jun 2024 16:04:41 +0100 Subject: [PATCH 02/13] created the base for the Attribute classes --- .../Attributes/SchemaDocument.php | 27 +++++++++++++++++ .../Attributes/SchemaDocumentField.php | 30 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/SchemaBuilder/Attributes/SchemaDocument.php create mode 100644 src/SchemaBuilder/Attributes/SchemaDocumentField.php diff --git a/src/SchemaBuilder/Attributes/SchemaDocument.php b/src/SchemaBuilder/Attributes/SchemaDocument.php new file mode 100644 index 0000000..b49adeb --- /dev/null +++ b/src/SchemaBuilder/Attributes/SchemaDocument.php @@ -0,0 +1,27 @@ +MaximumSize = $maxSize; + $this->Comment = $comment; + $this->MIMEType = $mimeType; + parent::__construct("SchemaDocument", [], []); + } +} diff --git a/src/SchemaBuilder/Attributes/SchemaDocumentField.php b/src/SchemaBuilder/Attributes/SchemaDocumentField.php new file mode 100644 index 0000000..c02926a --- /dev/null +++ b/src/SchemaBuilder/Attributes/SchemaDocumentField.php @@ -0,0 +1,30 @@ +Existence = $existence; + $this->Comment = $comment; + $this->ValidSchemas = $validSchemas; + parent::__construct("SchemaDocumentField", [], []); + } + +} From b27ceacaa1ae085ecbd7e56b6e2add63631efbd0 Mon Sep 17 00:00:00 2001 From: Cerys Date: Fri, 7 Jun 2024 16:05:00 +0100 Subject: [PATCH 03/13] can roughly create a schema --- src/SchemaBuilder/Helpers/SchemaBuilder.php | 52 +++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/SchemaBuilder/Helpers/SchemaBuilder.php diff --git a/src/SchemaBuilder/Helpers/SchemaBuilder.php b/src/SchemaBuilder/Helpers/SchemaBuilder.php new file mode 100644 index 0000000..a1589ce --- /dev/null +++ b/src/SchemaBuilder/Helpers/SchemaBuilder.php @@ -0,0 +1,52 @@ +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; + } +} From 7c6da14f8431601fb5a58a783ac2a158509a837e Mon Sep 17 00:00:00 2001 From: Cerys Date: Fri, 7 Jun 2024 16:05:12 +0100 Subject: [PATCH 04/13] enum for existence values --- src/Enumerators/SchemaFieldExistence.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/Enumerators/SchemaFieldExistence.php diff --git a/src/Enumerators/SchemaFieldExistence.php b/src/Enumerators/SchemaFieldExistence.php new file mode 100644 index 0000000..8a35583 --- /dev/null +++ b/src/Enumerators/SchemaFieldExistence.php @@ -0,0 +1,10 @@ + Date: Sun, 9 Jun 2024 01:52:49 +0100 Subject: [PATCH 05/13] more schema generation work - need to comment up the Schema Builder - general making it more strict --- .../Attributes/SchemaDocument.php | 3 ++- .../Attributes/SchemaDocumentField.php | 20 +++++++++------ .../{Helpers => }/SchemaBuilder.php | 25 +++++++++++++++---- 3 files changed, 34 insertions(+), 14 deletions(-) rename src/SchemaBuilder/{Helpers => }/SchemaBuilder.php (60%) diff --git a/src/SchemaBuilder/Attributes/SchemaDocument.php b/src/SchemaBuilder/Attributes/SchemaDocument.php index b49adeb..d450ef6 100644 --- a/src/SchemaBuilder/Attributes/SchemaDocument.php +++ b/src/SchemaBuilder/Attributes/SchemaDocument.php @@ -5,6 +5,7 @@ namespace Darksparrow\DeegraphPHP\SchemaBuilder\Attributes; use PhpParser\Node\Attribute; use ReflectionClass; +use PhpParser\Node\Name; #[\Attribute] class SchemaDocument extends Attribute @@ -22,6 +23,6 @@ class SchemaDocument extends Attribute $this->MaximumSize = $maxSize; $this->Comment = $comment; $this->MIMEType = $mimeType; - parent::__construct("SchemaDocument", [], []); + parent::__construct(new Name("SchemaDocument"), [], []); } } diff --git a/src/SchemaBuilder/Attributes/SchemaDocumentField.php b/src/SchemaBuilder/Attributes/SchemaDocumentField.php index c02926a..943fdd5 100644 --- a/src/SchemaBuilder/Attributes/SchemaDocumentField.php +++ b/src/SchemaBuilder/Attributes/SchemaDocumentField.php @@ -5,26 +5,30 @@ namespace Darksparrow\DeegraphPHP\SchemaBuilder\Attributes; use Darksparrow\DeegraphPHP\Enumerators\SchemaFieldExistence; use PhpParser\Node\Attribute; +use PhpParser\Node\Name; #[\Attribute] class SchemaDocumentField extends Attribute { + public string $Name; + public SchemaFieldExistence $Existence; public string $Comment; public array $ValidSchemas; public int $MaxSize; public function __construct( - SchemaFieldExistence $existence, - string $comment = "", - array $validSchemas = [], - int $maxSize = 0 + string $Name, + SchemaFieldExistence $Existence = SchemaFieldExistence::MAY, + string $Comment = "", + array $ValidSchemas = [], + int $MaxSize = 0 ) { - $this->Existence = $existence; - $this->Comment = $comment; - $this->ValidSchemas = $validSchemas; - parent::__construct("SchemaDocumentField", [], []); + $this->Existence = $Existence; + $this->Comment = $Comment; + $this->ValidSchemas = $ValidSchemas; + parent::__construct(new Name("SchemaDocumentField"), [], []); } } diff --git a/src/SchemaBuilder/Helpers/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php similarity index 60% rename from src/SchemaBuilder/Helpers/SchemaBuilder.php rename to src/SchemaBuilder/SchemaBuilder.php index a1589ce..7361904 100644 --- a/src/SchemaBuilder/Helpers/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -1,14 +1,18 @@ getProperties() as $temp) + $validAttributeNames[] = $temp->getName(); + $reflection = new ReflectionClass($targetSchema); $properties = $reflection->getProperties(); $attributes = $reflection->getAttributes()[0]; @@ -29,7 +33,7 @@ class SchemaBuilder */ foreach ($properties as $property) { $attributes = $property->getAttributes(); - $propertyName = $property->getName(); + $propertyName = ""; $propertySchema = []; foreach ($attributes as $attribute) @@ -39,10 +43,21 @@ class SchemaBuilder foreach($attribute->getArguments() as $key=>$value) { - if($value != "") - $propertySchema["@$key"] = $value; + if($key == "Name") + { + $propertyName = $value; + continue; + } + if(!in_array(needle: $key, haystack: $validAttributeNames)) + continue; + if($value == "") + continue; + + $propertySchema["@" . strtolower(preg_replace('/(? Date: Sun, 9 Jun 2024 02:00:31 +0100 Subject: [PATCH 06/13] will now throw an Exception if the Name isn't set --- src/Exceptions/SchemaNameUnsetException.php | 17 +++++++++++++++++ src/SchemaBuilder/SchemaBuilder.php | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/Exceptions/SchemaNameUnsetException.php diff --git a/src/Exceptions/SchemaNameUnsetException.php b/src/Exceptions/SchemaNameUnsetException.php new file mode 100644 index 0000000..7c46ffa --- /dev/null +++ b/src/Exceptions/SchemaNameUnsetException.php @@ -0,0 +1,17 @@ +message = "$message"; + $this->code = $code; + } +} diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index 7361904..444c7ed 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -2,11 +2,15 @@ namespace Darksparrow\DeegraphPHP\SchemaBuilder; +use Darksparrow\DeegraphPHP\Exceptions\SchemaNameUnsetException; use Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocumentField; use ReflectionClass; class SchemaBuilder { + /** + * @throws SchemaNameUnsetException + */ public static function GenerateSchema(object $targetSchema): array { $validAttributeNames = []; @@ -57,7 +61,7 @@ class SchemaBuilder } } if($propertyName == "") - throw new \Exception(); + throw new SchemaNameUnsetException(); $schema["$propertyName"] = $propertySchema; } From 2640c65f5a940e804d80834dbbe9fdf0bc04b000 Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 9 Jun 2024 02:17:27 +0100 Subject: [PATCH 07/13] general tidying up --- .../Attributes/SchemaDocument.php | 15 ++--- src/SchemaBuilder/SchemaBuilder.php | 59 ++++++++++++------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/SchemaBuilder/Attributes/SchemaDocument.php b/src/SchemaBuilder/Attributes/SchemaDocument.php index d450ef6..c7b6f8c 100644 --- a/src/SchemaBuilder/Attributes/SchemaDocument.php +++ b/src/SchemaBuilder/Attributes/SchemaDocument.php @@ -12,17 +12,18 @@ class SchemaDocument extends Attribute { public int $MaximumSize; public string $Comment; - public string $MIMEType; + public string $MimeType; public function __construct( - int $maxSize = 0, - string $comment = "", - string $mimeType = "" + string $Name, + int $MaximumSize = 0, + string $Comment = "", + string $MimeType = "" ) { - $this->MaximumSize = $maxSize; - $this->Comment = $comment; - $this->MIMEType = $mimeType; + $this->MaximumSize = $MaximumSize; + $this->Comment = $Comment; + $this->MimeType = $MimeType; parent::__construct(new Name("SchemaDocument"), [], []); } } diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index 444c7ed..2c0a9b1 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -3,44 +3,64 @@ namespace Darksparrow\DeegraphPHP\SchemaBuilder; use Darksparrow\DeegraphPHP\Exceptions\SchemaNameUnsetException; +use Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocument; use Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocumentField; use ReflectionClass; class SchemaBuilder { + private static function GetValidKeys() + { + $validDocumentAttributeNames = []; + $validPropertyAttributeNames = []; + + foreach((new ReflectionClass(new SchemaDocument("EMPTY")))->getProperties() as $temp) + $validDocumentAttributeNames[] = $temp->getName(); + foreach((new ReflectionClass(new SchemaDocumentField("EMPTY")))->getProperties() as $temp) + $validPropertyAttributeNames[] = $temp->getName(); + + return [$validDocumentAttributeNames, $validPropertyAttributeNames]; + } + private static function VerifyField(string $key, mixed $value, array $valids): bool + { + if(!in_array(needle: $key, haystack: $valids)) + return false; + if($value == "") + return false; + + return true; + } + private static function PascalCaseToSnakeCase(string $input): string + { + return strtolower(preg_replace('/(?getProperties() as $temp) - $validAttributeNames[] = $temp->getName(); - - $reflection = new ReflectionClass($targetSchema); - $properties = $reflection->getProperties(); - $attributes = $reflection->getAttributes()[0]; - $schema = []; + $validKeys = self::GetValidKeys(); + $reflection = new ReflectionClass($targetSchema); /* * Schema "meta-data" from here... */ - foreach($attributes->getArguments() as $key=>$value) - { - if($value != "") - $schema["@$key"] = $value; - } + foreach($reflection->getAttributes()[0]->getArguments() as $key=>$value) + if(self::VerifyField($key, $value, $validKeys[0])) + $schema["@" . self::PascalCaseToSnakeCase(input: $key)] = $value; /* * Property handling from here... */ - foreach ($properties as $property) { - $attributes = $property->getAttributes(); + foreach ($reflection->getProperties() as $property) + { $propertyName = ""; $propertySchema = []; - foreach ($attributes as $attribute) + foreach ($property->getAttributes() as $attribute) { if($attribute->getName() != "Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocumentField") continue; @@ -52,12 +72,9 @@ class SchemaBuilder $propertyName = $value; continue; } - if(!in_array(needle: $key, haystack: $validAttributeNames)) - continue; - if($value == "") - continue; - $propertySchema["@" . strtolower(preg_replace('/(? Date: Sun, 9 Jun 2024 02:19:09 +0100 Subject: [PATCH 08/13] bodged comments --- src/SchemaBuilder/SchemaBuilder.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index 2c0a9b1..70af5ea 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -9,7 +9,13 @@ use ReflectionClass; class SchemaBuilder { - private static function GetValidKeys() + /** + * Goes through the Attribute classes and makes a list of all the Properties they have. + * This is so if a user adds another variable to the Attribute constructor, it won't appear in the final Schema. + * + * @return array[] + */ + private static function GetValidKeys(): array { $validDocumentAttributeNames = []; $validPropertyAttributeNames = []; @@ -21,6 +27,15 @@ class SchemaBuilder return [$validDocumentAttributeNames, $validPropertyAttributeNames]; } + + /** + * Checks to see if a value is "okay" for a Schema. + * + * @param string $key + * @param mixed $value + * @param array $valids + * @return bool + */ private static function VerifyField(string $key, mixed $value, array $valids): bool { if(!in_array(needle: $key, haystack: $valids)) @@ -30,6 +45,13 @@ class SchemaBuilder return true; } + + /** + * Just converts PascalCase to snake_case. + * + * @param string $input + * @return string + */ private static function PascalCaseToSnakeCase(string $input): string { return strtolower(preg_replace('/(? Date: Sun, 9 Jun 2024 02:31:21 +0100 Subject: [PATCH 09/13] added `MimeType` as as a Field --- src/SchemaBuilder/Attributes/SchemaDocumentField.php | 5 ++++- src/SchemaBuilder/SchemaBuilder.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/SchemaBuilder/Attributes/SchemaDocumentField.php b/src/SchemaBuilder/Attributes/SchemaDocumentField.php index 943fdd5..1bd026f 100644 --- a/src/SchemaBuilder/Attributes/SchemaDocumentField.php +++ b/src/SchemaBuilder/Attributes/SchemaDocumentField.php @@ -16,18 +16,21 @@ class SchemaDocumentField extends Attribute public string $Comment; public array $ValidSchemas; public int $MaxSize; + public string $MimeType; public function __construct( string $Name, SchemaFieldExistence $Existence = SchemaFieldExistence::MAY, string $Comment = "", array $ValidSchemas = [], - int $MaxSize = 0 + int $MaxSize = 0, + string $MimeType = "", ) { $this->Existence = $Existence; $this->Comment = $Comment; $this->ValidSchemas = $ValidSchemas; + $this->MimeType = $MimeType; parent::__construct(new Name("SchemaDocumentField"), [], []); } diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index 70af5ea..9b39174 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -12,7 +12,7 @@ class SchemaBuilder /** * Goes through the Attribute classes and makes a list of all the Properties they have. * This is so if a user adds another variable to the Attribute constructor, it won't appear in the final Schema. - * + * * @return array[] */ private static function GetValidKeys(): array From 250f919cc8596897c26d12ed2a66ec0b8c16b90a Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 9 Jun 2024 02:31:45 +0100 Subject: [PATCH 10/13] added an example (source see desc.) https://schemas.auxiliumsoftware.co.uk/v1/message.json --- Examples/SchemaBuilder/Schemas/Message.php | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Examples/SchemaBuilder/Schemas/Message.php diff --git a/Examples/SchemaBuilder/Schemas/Message.php b/Examples/SchemaBuilder/Schemas/Message.php new file mode 100644 index 0000000..58883ec --- /dev/null +++ b/Examples/SchemaBuilder/Schemas/Message.php @@ -0,0 +1,62 @@ +"All direct recipients should be addressed", + "@valid_schemas"=>[ + "https://schemas.auxiliumsoftware.co.uk/v1/user.json" + ] + ] + )] + public string $IndirectRecipients; + + #[SchemaDocumentField( + Name: "sent_at", + Existence: SchemaFieldExistence::SHOULD, + Comment: "The date the message was actually sent, if supplied MUST be in ISO 8601 format", + MaxSize: 64, + MimeType: "text/plain", + )] + public string $SentAt; +} From 923c249fd878b91929cf7fbd09da038de159885f Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 9 Jun 2024 02:33:56 +0100 Subject: [PATCH 11/13] see desc. I forgot to "uninclude" some code in the last commit as it doesn't do anything at the moment and doesn't contribute to the Schema generation... but hey ho, may as well throw the rest in haha! --- Examples/SchemaBuilder/Schemas/Message.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Examples/SchemaBuilder/Schemas/Message.php b/Examples/SchemaBuilder/Schemas/Message.php index 58883ec..15b3bda 100644 --- a/Examples/SchemaBuilder/Schemas/Message.php +++ b/Examples/SchemaBuilder/Schemas/Message.php @@ -31,6 +31,12 @@ class Message "https://schemas.auxiliumsoftware.co.uk/v1/collection.json" ], MaxSize: 0, + Child: [ + "@comment"=>"All direct recipients should be addressed", + "@valid_schemas"=>[ + "https://schemas.auxiliumsoftware.co.uk/v1/user.json" + ] + ] )] public string $Recipients; From f7e4eb0b781505d0a23ee0d6ce36768371646e13 Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 9 Jun 2024 02:38:10 +0100 Subject: [PATCH 12/13] included code in the repo to generate the Message example schema --- .../ExampleScripts/generateMessageSchema.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php diff --git a/Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php b/Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php new file mode 100644 index 0000000..ddc59c2 --- /dev/null +++ b/Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php @@ -0,0 +1,15 @@ + Date: Sun, 9 Jun 2024 15:14:09 +0100 Subject: [PATCH 13/13] moving all the schema code to another repo https://git.darksparrow.uk/Packages_PHP/AuxiliumSchemaBuilder --- .../ExampleScripts/generateMessageSchema.php | 15 --- Examples/SchemaBuilder/Schemas/Message.php | 68 ----------- src/Enumerators/SchemaFieldExistence.php | 10 -- src/Exceptions/SchemaNameUnsetException.php | 17 --- .../Attributes/SchemaDocument.php | 29 ----- .../Attributes/SchemaDocumentField.php | 37 ------ src/SchemaBuilder/SchemaBuilder.php | 110 ------------------ 7 files changed, 286 deletions(-) delete mode 100644 Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php delete mode 100644 Examples/SchemaBuilder/Schemas/Message.php delete mode 100644 src/Enumerators/SchemaFieldExistence.php delete mode 100644 src/Exceptions/SchemaNameUnsetException.php delete mode 100644 src/SchemaBuilder/Attributes/SchemaDocument.php delete mode 100644 src/SchemaBuilder/Attributes/SchemaDocumentField.php delete mode 100644 src/SchemaBuilder/SchemaBuilder.php diff --git a/Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php b/Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php deleted file mode 100644 index ddc59c2..0000000 --- a/Examples/SchemaBuilder/ExampleScripts/generateMessageSchema.php +++ /dev/null @@ -1,15 +0,0 @@ -"All direct recipients should be addressed", - "@valid_schemas"=>[ - "https://schemas.auxiliumsoftware.co.uk/v1/user.json" - ] - ] - )] - public string $Recipients; - - #[SchemaDocumentField( - Name: "indirect_recipients", - Existence: SchemaFieldExistence::SHOULD, - Comment: "All cc'd recipients that are known should be attached", - ValidSchemas: [ - "https://schemas.auxiliumsoftware.co.uk/v1/collection.json" - ], - MaxSize: 0, - Child: [ - "@comment"=>"All direct recipients should be addressed", - "@valid_schemas"=>[ - "https://schemas.auxiliumsoftware.co.uk/v1/user.json" - ] - ] - )] - public string $IndirectRecipients; - - #[SchemaDocumentField( - Name: "sent_at", - Existence: SchemaFieldExistence::SHOULD, - Comment: "The date the message was actually sent, if supplied MUST be in ISO 8601 format", - MaxSize: 64, - MimeType: "text/plain", - )] - public string $SentAt; -} diff --git a/src/Enumerators/SchemaFieldExistence.php b/src/Enumerators/SchemaFieldExistence.php deleted file mode 100644 index 8a35583..0000000 --- a/src/Enumerators/SchemaFieldExistence.php +++ /dev/null @@ -1,10 +0,0 @@ -message = "$message"; - $this->code = $code; - } -} diff --git a/src/SchemaBuilder/Attributes/SchemaDocument.php b/src/SchemaBuilder/Attributes/SchemaDocument.php deleted file mode 100644 index c7b6f8c..0000000 --- a/src/SchemaBuilder/Attributes/SchemaDocument.php +++ /dev/null @@ -1,29 +0,0 @@ -MaximumSize = $MaximumSize; - $this->Comment = $Comment; - $this->MimeType = $MimeType; - parent::__construct(new Name("SchemaDocument"), [], []); - } -} diff --git a/src/SchemaBuilder/Attributes/SchemaDocumentField.php b/src/SchemaBuilder/Attributes/SchemaDocumentField.php deleted file mode 100644 index 1bd026f..0000000 --- a/src/SchemaBuilder/Attributes/SchemaDocumentField.php +++ /dev/null @@ -1,37 +0,0 @@ -Existence = $Existence; - $this->Comment = $Comment; - $this->ValidSchemas = $ValidSchemas; - $this->MimeType = $MimeType; - parent::__construct(new Name("SchemaDocumentField"), [], []); - } - -} diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php deleted file mode 100644 index 9b39174..0000000 --- a/src/SchemaBuilder/SchemaBuilder.php +++ /dev/null @@ -1,110 +0,0 @@ -getProperties() as $temp) - $validDocumentAttributeNames[] = $temp->getName(); - foreach((new ReflectionClass(new SchemaDocumentField("EMPTY")))->getProperties() as $temp) - $validPropertyAttributeNames[] = $temp->getName(); - - return [$validDocumentAttributeNames, $validPropertyAttributeNames]; - } - - /** - * Checks to see if a value is "okay" for a Schema. - * - * @param string $key - * @param mixed $value - * @param array $valids - * @return bool - */ - private static function VerifyField(string $key, mixed $value, array $valids): bool - { - if(!in_array(needle: $key, haystack: $valids)) - return false; - if($value == "") - return false; - - return true; - } - - /** - * Just converts PascalCase to snake_case. - * - * @param string $input - * @return string - */ - private static function PascalCaseToSnakeCase(string $input): string - { - return strtolower(preg_replace('/(?getAttributes()[0]->getArguments() as $key=>$value) - if(self::VerifyField($key, $value, $validKeys[0])) - $schema["@" . self::PascalCaseToSnakeCase(input: $key)] = $value; - - /* - * Property handling from here... - */ - foreach ($reflection->getProperties() as $property) - { - $propertyName = ""; - $propertySchema = []; - - foreach ($property->getAttributes() as $attribute) - { - if($attribute->getName() != "Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocumentField") - continue; - - foreach($attribute->getArguments() as $key=>$value) - { - if($key == "Name") - { - $propertyName = $value; - continue; - } - - if(self::VerifyField($key, $value, $validKeys[1])) - $propertySchema["@" . self::PascalCaseToSnakeCase(input: $key)] = $value; - } - } - if($propertyName == "") - throw new SchemaNameUnsetException(); - - $schema["$propertyName"] = $propertySchema; - } - - return $schema; - } -}