Browse Source

started work on being able to generate schema URLs

dev
Cerys 4 weeks ago
parent
commit
65f3d9e296
  1. 2
      examples/Schemas/Message.php
  2. 4
      examples/Schemas/Organisation.php
  3. 10
      phpunit.xml
  4. 2
      src/Attributes/SchemaDocument.php
  5. 24
      src/Utilities/URLHandling.php
  6. 20
      tests/SchemaURITest.php
  7. 3
      tests/bootstrap.php

2
examples/Schemas/Message.php

@ -9,7 +9,7 @@ use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument;
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField;
#[SchemaDocument(
Name: "Message",
Name: "message",
MimeType: "message/rfc822",
)]
class Message

4
examples/Schemas/Organisation.php

@ -1,4 +1,4 @@
<?phpSchemaDocumentChildField
<?php
namespace Darksparrow\AuxiliumSchemaBuilder\Examples\SchemaBuilder\Schemas;
@ -11,7 +11,7 @@ use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField;
use Darksparrow\AuxiliumSchemaBuilder\Interfaces\SchemaDocumentInterface;
#[SchemaDocument(
Name: "Message",
Name: "organisation",
MaxSize: 0,
Comment: "The organisation object itself SHOULD not have a value",
MimeType: "message/rfc822",

10
phpunit.xml

@ -0,0 +1,10 @@
<phpunit
colors="true"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Darksparrow/AuxiliumSchemaBuilder Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

2
src/Attributes/SchemaDocument.php

@ -10,6 +10,7 @@ use PhpParser\Node\Name;
#[\Attribute]
class SchemaDocument extends Attribute
{
public string $Name;
public int $MaxSize;
public string $Comment;
public string $MimeType;
@ -21,6 +22,7 @@ class SchemaDocument extends Attribute
string $MimeType = ""
)
{
$this->Name = $Name;
$this->MaxSize = $MaxSize;
$this->Comment = $Comment;
$this->MimeType = $MimeType;

24
src/Utilities/URLHandling.php

@ -0,0 +1,24 @@
<?php
namespace Darksparrow\AuxiliumSchemaBuilder\Utilities;
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument;
use ReflectionClass;
class URLHandling
{
public static string $URLBase = "https://schemas.auxiliumsoftware.co.uk/v1/";
public static function GetURLForSchema(string $targetSchemaClassName): string
{
$reflection = new ReflectionClass(new $targetSchemaClassName());
foreach($reflection->getAttributes() as $attribute)
{
if($attribute->getName() === SchemaDocument::class)
{
$name = $attribute->getArguments()["Name"];
return self::$URLBase . $name . ".json";
}
}
die();
}
}

20
tests/SchemaURITest.php

@ -0,0 +1,20 @@
<?php
require_once __DIR__ . "/../examples/Schemas/Message.php";
require_once __DIR__ . "/../examples/Schemas/Organisation.php";
use Darksparrow\AuxiliumSchemaBuilder\Examples\SchemaBuilder\Schemas\Message;
use Darksparrow\AuxiliumSchemaBuilder\Utilities\URLHandling;
use PHPUnit\Framework\TestCase;
final class SchemaURITest extends TestCase
{
public function test0()
{
URLHandling::$URLBase = "https://schemas.auxiliumsoftware.co.uk/v1/";
self::assertEquals(
expected: "https://schemas.auxiliumsoftware.co.uk/v1/message.json",
actual: URLHandling::GetURLForSchema(Message::class),
);
}
}

3
tests/bootstrap.php

@ -0,0 +1,3 @@
<?php
namespace tests;
Loading…
Cancel
Save