Browse Source

done away with the child field in favour of just nesting

dev
Cerys 3 weeks ago
parent
commit
d81a73db82
  1. 24
      src/Attributes/SchemaDocumentChildField.php
  2. 2
      src/Attributes/SchemaDocumentField.php
  3. 26
      src/SchemaBuilder/SchemaBuilder.php

24
src/Attributes/SchemaDocumentChildField.php

@ -1,24 +0,0 @@
<?php
namespace Darksparrow\AuxiliumSchemaBuilder\Attributes;
use PhpParser\Node\Attribute;
use PhpParser\Node\Name;
#[\Attribute]
class SchemaDocumentChildField extends Attribute
{
public string $Comment;
public array $ValidSchemas;
public function __construct(
string $Comment,
array $ValidSchemas = [],
)
{
$this->Comment = $Comment;
$this->ValidSchemas = $ValidSchemas;
parent::__construct(new Name("SchemaDocumentChildField"), [], []);
}
}

2
src/Attributes/SchemaDocumentField.php

@ -25,7 +25,7 @@ class SchemaDocumentField extends Attribute
array $ValidSchemas = [], array $ValidSchemas = [],
int $MaxSize = 0, int $MaxSize = 0,
string $MimeType = "", string $MimeType = "",
SchemaDocumentChildField $Child = null SchemaDocumentField $Child = null
) )
{ {
$this->Existence = $Existence; $this->Existence = $Existence;

26
src/SchemaBuilder/SchemaBuilder.php

@ -7,6 +7,7 @@ use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument;
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField; use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField;
use Darksparrow\AuxiliumSchemaBuilder\Utilities\URLHandling; use Darksparrow\AuxiliumSchemaBuilder\Utilities\URLHandling;
use JetBrains\PhpStorm\NoReturn; use JetBrains\PhpStorm\NoReturn;
use PHPUnit\Util\Exception;
use ReflectionClass; use ReflectionClass;
class SchemaBuilder class SchemaBuilder
@ -81,6 +82,9 @@ class SchemaBuilder
*/ */
foreach ($reflection->getProperties() as $property) foreach ($reflection->getProperties() as $property)
{ {
$classNameRegex = '/^([\\]*)?[a-zA-Z_][a-zA-Z0-9_]*)(([\\]*[a-zA-Z0-9_]*)*)$/';
$urlRegex = '/^https?:\/\/[^\s$.?#].[^\s]*$/i';
$propertyName = ""; $propertyName = "";
$propertySchema = []; $propertySchema = [];
@ -101,24 +105,38 @@ class SchemaBuilder
"@comment" => $value->Comment, "@comment" => $value->Comment,
"@valid_schemas" => $value->ValidSchemas, "@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") elseif($key == "ValidSchemas")
{ {
$propertySchema["@valid_schemas"] = []; $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) foreach($value as $validSchema)
{ {
if (preg_match($classNameRegex, $validSchema)) if (preg_match($classNameRegex, $validSchema))
$propertySchema["@valid_schemas"][] = URLHandling::GetURLForSchema($validSchema); $propertySchema["@valid_schemas"][] = URLHandling::GetURLForSchema($validSchema);
elseif (preg_match($urlRegex, $validSchema)) elseif (preg_match($urlRegex, $validSchema))
$propertySchema["@valid_schemas"][] = $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 == "") if($propertyName == "")

Loading…
Cancel
Save