From 5873796bc645d2e91bc3bd150f2822554f218047 Mon Sep 17 00:00:00 2001 From: Cerys Date: Sun, 1 Dec 2024 19:57:36 +0000 Subject: [PATCH] should now be able to put either class names or URLs in --- src/SchemaBuilder/SchemaBuilder.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index 6da8816..4d75d16 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -5,6 +5,7 @@ namespace Darksparrow\AuxiliumSchemaBuilder\SchemaBuilder; use Darksparrow\AuxiliumSchemaBuilder\Exceptions\SchemaDocumentFieldNameUnsetException; use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField; +use Darksparrow\AuxiliumSchemaBuilder\Utilities\URLHandling; use JetBrains\PhpStorm\NoReturn; use ReflectionClass; @@ -105,6 +106,19 @@ class SchemaBuilder { $propertySchema["@" . self::PascalCaseToSnakeCase(input: $key)] = $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; + } + } } } if($propertyName == "")