From 870368fa8caec016ac10b557858ffc2275d33502 Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 9 Jun 2024 15:14:09 +0100 Subject: [PATCH] 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; - } -}