From d81a73db820aa92dd35ebf79960031133ba54937 Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 1 Dec 2024 20:20:46 +0000 Subject: [PATCH] done away with the child field in favour of just nesting --- src/Attributes/SchemaDocumentChildField.php | 24 ------------------- src/Attributes/SchemaDocumentField.php | 2 +- src/SchemaBuilder/SchemaBuilder.php | 26 +++++++++++++++++---- 3 files changed, 23 insertions(+), 29 deletions(-) delete mode 100644 src/Attributes/SchemaDocumentChildField.php diff --git a/src/Attributes/SchemaDocumentChildField.php b/src/Attributes/SchemaDocumentChildField.php deleted file mode 100644 index 7c0aa7f..0000000 --- a/src/Attributes/SchemaDocumentChildField.php +++ /dev/null @@ -1,24 +0,0 @@ -Comment = $Comment; - $this->ValidSchemas = $ValidSchemas; - parent::__construct(new Name("SchemaDocumentChildField"), [], []); - } - -} diff --git a/src/Attributes/SchemaDocumentField.php b/src/Attributes/SchemaDocumentField.php index 16c3b3d..d4832bc 100644 --- a/src/Attributes/SchemaDocumentField.php +++ b/src/Attributes/SchemaDocumentField.php @@ -25,7 +25,7 @@ class SchemaDocumentField extends Attribute array $ValidSchemas = [], int $MaxSize = 0, string $MimeType = "", - SchemaDocumentChildField $Child = null + SchemaDocumentField $Child = null ) { $this->Existence = $Existence; diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index 4d75d16..f0b9ae1 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -7,6 +7,7 @@ use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField; use Darksparrow\AuxiliumSchemaBuilder\Utilities\URLHandling; use JetBrains\PhpStorm\NoReturn; +use PHPUnit\Util\Exception; use ReflectionClass; class SchemaBuilder @@ -81,6 +82,9 @@ class SchemaBuilder */ foreach ($reflection->getProperties() as $property) { + $classNameRegex = '/^([\\]*)?[a-zA-Z_][a-zA-Z0-9_]*)(([\\]*[a-zA-Z0-9_]*)*)$/'; + $urlRegex = '/^https?:\/\/[^\s$.?#].[^\s]*$/i'; + $propertyName = ""; $propertySchema = []; @@ -101,24 +105,38 @@ class SchemaBuilder "@comment" => $value->Comment, "@valid_schemas" => $value->ValidSchemas, ]; + $propertySchema["@valid_schemas"] = []; + foreach($value as $validSchema) + { + if (preg_match($classNameRegex, $validSchema)) + $propertySchema["@valid_schemas"][] = URLHandling::GetURLForSchema($validSchema); + elseif (preg_match($urlRegex, $validSchema)) + $propertySchema["@valid_schemas"][] = $validSchema; + else + $propertySchema["@valid_schemas"][] = "test123"; + } } - elseif(self::VerifyField($key, $value, $validKeys[1])) + elseif($key == "Existance") { - $propertySchema["@" . self::PascalCaseToSnakeCase(input: $key)] = $value; + $propertySchema["#"] = $value->value; } elseif($key == "ValidSchemas") { $propertySchema["@valid_schemas"] = []; - $classNameRegex = '/^(\\\\?[A-Z][a-zA-Z0-9_]*)((\\\\[A-Z][a-zA-Z0-9_]*)*)$/'; - $urlRegex = '/^https?:\/\/[^\s$.?#].[^\s]*$/i'; foreach($value as $validSchema) { if (preg_match($classNameRegex, $validSchema)) $propertySchema["@valid_schemas"][] = URLHandling::GetURLForSchema($validSchema); elseif (preg_match($urlRegex, $validSchema)) $propertySchema["@valid_schemas"][] = $validSchema; + else + $propertySchema["@valid_schemas"][] = "test123"; } } + elseif(self::VerifyField($key, $value, $validKeys[1])) + { + $propertySchema["@" . self::PascalCaseToSnakeCase(input: $key)] = $value; + } } } if($propertyName == "")