cerys
1 week ago
19 changed files with 929 additions and 463 deletions
File diff suppressed because it is too large
@ -0,0 +1,97 @@ |
|||
<?php |
|||
|
|||
namespace Auxilium\Schemas; |
|||
|
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Enumerators\SchemaFieldExistence; |
|||
|
|||
#[SchemaDocument( |
|||
Name: "case", |
|||
Comment: "The case object itself SHOULD not have a value" |
|||
)] |
|||
class CaseSchema |
|||
{ |
|||
#[SchemaDocumentField( |
|||
Name: "title", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be a short description of what the case is about", |
|||
MaxSize: 2048, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $Title; |
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "clients", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all the clients involved in the case", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "clients", |
|||
Comment: "", |
|||
ValidSchemas: [ |
|||
UserSchema::class, |
|||
] |
|||
), |
|||
)] |
|||
public array $Clients; |
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "workers", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all staff working on the case", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "workers", |
|||
Comment: "", |
|||
ValidSchemas: [ |
|||
UserSchema::class, |
|||
OrganisationSchema::class, |
|||
] |
|||
), |
|||
)] |
|||
public array $Workers; |
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "documents", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all the case documents", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "documents", |
|||
Comment: "", |
|||
ValidSchemas: [ |
|||
DocumentSchema::class, |
|||
] |
|||
), |
|||
)] |
|||
public array $Documents; |
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "messages", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all messages that relate to this case", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "messages", |
|||
Comment: "", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
] |
|||
), |
|||
)] |
|||
public array $Messages; |
|||
} |
|||
|
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
namespace Auxilium\Schemas; |
|||
|
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; |
|||
|
|||
#[SchemaDocument( |
|||
Name: "collection", |
|||
MaxSize: 0, |
|||
Comment: "This is intended as an inheritable schema used to signify to software that it SHOULD display the numeric properties of this node as an inlined list", |
|||
)] |
|||
class CollectionSchema |
|||
{ |
|||
|
|||
} |
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
namespace Auxilium\Schemas; |
|||
|
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Enumerators\SchemaFieldExistence; |
|||
|
|||
#[SchemaDocument( |
|||
Name: "document", |
|||
Comment: "Any given document SHOULD have metadata attached", |
|||
)] |
|||
class DocumentSchema |
|||
{ |
|||
#[SchemaDocumentField( |
|||
Name: "file_name", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "The filename SHOULD NOT contain an extension, this SHOULD be added by the application based on the file's mime type", |
|||
MaxSize: 256, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $FileName; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "created", |
|||
Existence: SchemaFieldExistence::MAY, |
|||
Comment: "The creation date, if supplied MUST be in ISO 8601 format", |
|||
MaxSize: 64, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $Created; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "modified", |
|||
Existence: SchemaFieldExistence::MAY, |
|||
Comment: "The last modified date, if supplied MUST be in ISO 8601 format", |
|||
MaxSize: 64, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $Modified; |
|||
} |
@ -0,0 +1,14 @@ |
|||
<?php |
|||
|
|||
namespace Auxilium\Schemas; |
|||
|
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; |
|||
|
|||
#[SchemaDocument( |
|||
Name: "enum", |
|||
Comment: "This is intended as an inheritable schema used to signify to software that it SHOULD be interpreted as a enumerable choice value that can be decoded based on its schema", |
|||
)] |
|||
class EnumSchema |
|||
{ |
|||
|
|||
} |
@ -0,0 +1,103 @@ |
|||
<?php |
|||
|
|||
|
|||
namespace Auxilium\Schemas; |
|||
|
|||
use Darksparrow\AuxiliumSchemaBuilder\Enumerators\SchemaFieldExistence; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Interfaces\SchemaDocumentInterface; |
|||
|
|||
#[SchemaDocument( |
|||
Name: "organisation", |
|||
MaxSize: 0, |
|||
Comment: "The organisation object itself SHOULD not have a value", |
|||
)] |
|||
class OrganisationSchema |
|||
{ |
|||
#[SchemaDocumentField( |
|||
Name: "name", |
|||
Existence: SchemaFieldExistence::MUST, |
|||
Comment: "This MUST be the organisation's name", |
|||
MaxSize: 2048, |
|||
MimeType: "text/plain", |
|||
Children: [ |
|||
new SchemaDocumentField( |
|||
Name: "trading_as", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be the organisation's short trading name, or the abbreviation they would usually go by", |
|||
MaxSize: 256, |
|||
MimeType: "text/plain", |
|||
) |
|||
] |
|||
)] |
|||
public string $Name; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "departments", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all sub-organisations if applicable", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "departments", |
|||
Comment: null, |
|||
ValidSchemas: [ |
|||
OrganisationSchema::class, |
|||
], |
|||
), |
|||
)] |
|||
public array $Departments; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "cases", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all the cases the organisation is either directly working on or the client of", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "cases", |
|||
Comment: null, |
|||
ValidSchemas: [ |
|||
CaseSchema::class, |
|||
], |
|||
), |
|||
)] |
|||
public array $Cases; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "staff", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all the staff that cannot be categorised into departments, or in the case of small organisations with no departments, all staff", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "staff", |
|||
Comment: null, |
|||
ValidSchemas: [ |
|||
"https://schemas.auxiliumsoftware.co.uk/v1/user.json", |
|||
], |
|||
), |
|||
)] |
|||
public array $Staff; |
|||
|
|||
|
|||
/* |
|||
public function __construct(array $data) |
|||
{ |
|||
$this->Name = $data["name"]; |
|||
$this->Departments = $data["departments"]; |
|||
$this->Cases = $data["cases"]; |
|||
$this->Staff = $data["staff"]; |
|||
} |
|||
*/ |
|||
} |
@ -0,0 +1,169 @@ |
|||
<?php |
|||
|
|||
namespace Auxilium\Schemas; |
|||
|
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocument; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Attributes\SchemaDocumentField; |
|||
use Darksparrow\AuxiliumSchemaBuilder\Enumerators\SchemaFieldExistence; |
|||
|
|||
#[SchemaDocument( |
|||
Name: "user", |
|||
MaxSize: 0, |
|||
Comment: "The user object itself SHOULD not have a value", |
|||
)] |
|||
class UserSchema |
|||
{ |
|||
#[SchemaDocumentField( |
|||
Name: "name", |
|||
Existence: SchemaFieldExistence::MUST, |
|||
Comment: "This MUST be the user's full name", |
|||
MaxSize: 2048, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $Name; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "display_name", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be the user's first name or 'preferred' name used for UI", |
|||
MaxSize: 256, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $DisplayName; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "contact_email", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD NOT be used for unverified user input", |
|||
MaxSize: 512, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $ContactEmail; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "contact_email", |
|||
Existence: SchemaFieldExistence::MAY, |
|||
Comment: "This SHOULD be used for unverified user input instead of the 'contact_email' field", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "auxiliary_emails", |
|||
MaxSize: 512, |
|||
MimeType: "text/plain", |
|||
) |
|||
)] |
|||
public array $AuxiliaryEmails; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "contact_phone_number", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD include country code, and SHOULD NOT include spaces", |
|||
MaxSize: 64, |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $ContactPhoneNumber; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "auxiliary_phone_numbers", |
|||
Existence: SchemaFieldExistence::MAY, |
|||
Comment: "This SHOULD be used for phone numbers that need to be on record, but shouldn't be used for contact", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "auxiliary_phone_numbers", |
|||
Comment: "This SHOULD include country code, and SHOULD NOT include spaces", |
|||
MaxSize: 64, |
|||
MimeType: "text/plain", |
|||
) |
|||
)] |
|||
public array $AuxiliaryPhoneNumbers; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "contact_address", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be a full address, suitable for international postage", |
|||
MimeType: "text/plain", |
|||
)] |
|||
public string $ContactAddress; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "auxiliary_addresses", |
|||
Existence: SchemaFieldExistence::MAY, |
|||
Comment: "This SHOULD be used for addresses that need to be on record, but shouldn't be used for contact", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "auxiliary_addresses", |
|||
Comment: "This MAY be a full address, or a shortened address only suitable for local mail", |
|||
MimeType: "text/plain", |
|||
) |
|||
)] |
|||
public array $AuxiliaryAddresses; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "documents", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all the user's documents", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "documents", |
|||
ValidSchemas: [ |
|||
DocumentSchema::class, |
|||
] |
|||
) |
|||
)] |
|||
public array $Documents; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "cases", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all the cases the user is either directly working on or the client of", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "cases", |
|||
ValidSchemas: [ |
|||
CaseSchema::class, |
|||
] |
|||
) |
|||
)] |
|||
public array $Cases; |
|||
|
|||
|
|||
#[SchemaDocumentField( |
|||
Name: "messages", |
|||
Existence: SchemaFieldExistence::SHOULD, |
|||
Comment: "This SHOULD be an 'array node' of all the user's send and recieved messages", |
|||
ValidSchemas: [ |
|||
CollectionSchema::class, |
|||
], |
|||
MaxSize: 0, |
|||
Child: new SchemaDocumentField( |
|||
Name: "messages", |
|||
ValidSchemas: [ |
|||
MessageSchema::class, |
|||
] |
|||
) |
|||
)] |
|||
public array $Messages; |
|||
} |
@ -0,0 +1,10 @@ |
|||
<phpunit |
|||
colors="true" |
|||
bootstrap="tests/bootstrap.php" |
|||
> |
|||
<testsuites> |
|||
<testsuite name="Darksparrow/AuxiliumSchemaBuilder Tests"> |
|||
<directory>tests</directory> |
|||
</testsuite> |
|||
</testsuites> |
|||
</phpunit> |
@ -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"), [], []); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,8 @@ |
|||
<?php |
|||
|
|||
namespace Darksparrow\AuxiliumSchemaBuilder\Interfaces; |
|||
|
|||
interface SchemaDocumentInterface |
|||
{ |
|||
public function __construct(array $data); |
|||
} |
@ -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"; |
|||
} |
|||
} |
|||
throw new \Exception("Could not determine URL for schema " . $targetSchemaClassName . "."); |
|||
} |
|||
} |
@ -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), |
|||
); |
|||
} |
|||
} |
@ -0,0 +1,3 @@ |
|||
<?php |
|||
|
|||
namespace tests; |
Loading…
Reference in new issue