From b2c7c5b008d4f6dc99d16b05139404dbdda111c5 Mon Sep 17 00:00:00 2001 From: Cerys Lewis Date: Tue, 12 Nov 2024 15:34:25 +0000 Subject: [PATCH] now handles "#" elements --- .../ExampleScripts/generateMessageSchema.php | 4 +- Examples/Schemas/Message.php | 19 ++-- composer.lock | 103 +++++++++--------- src/Attributes/SchemaDocumentChildField.php | 24 ++++ src/Attributes/SchemaDocumentField.php | 1 + src/SchemaBuilder/SchemaBuilder.php | 18 ++- 6 files changed, 96 insertions(+), 73 deletions(-) create mode 100644 src/Attributes/SchemaDocumentChildField.php diff --git a/Examples/ExampleScripts/generateMessageSchema.php b/Examples/ExampleScripts/generateMessageSchema.php index 12de246..7d54e7b 100644 --- a/Examples/ExampleScripts/generateMessageSchema.php +++ b/Examples/ExampleScripts/generateMessageSchema.php @@ -3,8 +3,8 @@ namespace Darksparrow\Deegraph\examples\SchemaBuilder; -require_once __DIR__ . "/../../../vendor/autoload.php"; -require_once __DIR__ . "/../../../Examples/SchemaBuilder/Schemas/Message.php"; +require_once __DIR__ . "/../../vendor/autoload.php"; +require_once __DIR__ . "/../../Examples/Schemas/Message.php"; use Darksparrow\Deegraph\Examples\SchemaBuilder\Schemas\Message; use Darksparrow\AuxiliumSchemaBuilder\SchemaBuilder\SchemaBuilder; diff --git a/Examples/Schemas/Message.php b/Examples/Schemas/Message.php index 25602f1..021bbc5 100644 --- a/Examples/Schemas/Message.php +++ b/Examples/Schemas/Message.php @@ -1,8 +1,9 @@ "All direct recipients should be addressed", - "@valid_schemas"=>[ + Child: new SchemaDocumentChildField( + Comment: "All direct recipients should be addressed", + ValidSchemas: [ "https://schemas.auxiliumsoftware.co.uk/v1/user.json" ] - ] + ), )] public string $Recipients; @@ -48,12 +49,12 @@ class Message "https://schemas.auxiliumsoftware.co.uk/v1/collection.json" ], MaxSize: 0, - Child: [ - "@comment"=>"All direct recipients should be addressed", - "@valid_schemas"=>[ + Child: new SchemaDocumentChildField( + Comment: "All direct recipients should be addressed", + ValidSchemas: [ "https://schemas.auxiliumsoftware.co.uk/v1/user.json" ] - ] + ), )] public string $IndirectRecipients; diff --git a/composer.lock b/composer.lock index ad5103b..43b3a2a 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "9955122a490d18ce723cf9014b196c126222c180" + "reference": "be6a7e86c74841eac964ae16853e4036a6a319d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/9955122a490d18ce723cf9014b196c126222c180", - "reference": "9955122a490d18ce723cf9014b196c126222c180", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/be6a7e86c74841eac964ae16853e4036a6a319d0", + "reference": "be6a7e86c74841eac964ae16853e4036a6a319d0", "shasum": "" }, "require": { @@ -75,7 +75,7 @@ "type": "tidelift" } ], - "time": "2024-05-05T15:09:38+00:00" + "time": "2024-10-16T22:06:28+00:00" }, { "name": "myclabs/deep-copy", @@ -83,12 +83,12 @@ "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "2f5294676c802a62b0549f6bc8983f14294ce369" + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/2f5294676c802a62b0549f6bc8983f14294ce369", - "reference": "2f5294676c802a62b0549f6bc8983f14294ce369", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", "shasum": "" }, "require": { @@ -128,7 +128,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.x" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" }, "funding": [ { @@ -136,20 +136,20 @@ "type": "tidelift" } ], - "time": "2024-02-10T11:10:03+00:00" + "time": "2024-11-08T17:47:46+00:00" }, { "name": "nikic/php-parser", - "version": "dev-master", + "version": "v5.3.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "daaadc3bae458908aa477b90a8932e7da9253f22" + "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/daaadc3bae458908aa477b90a8932e7da9253f22", - "reference": "daaadc3bae458908aa477b90a8932e7da9253f22", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8eea230464783aa9671db8eea6f8c6ac5285794b", + "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b", "shasum": "" }, "require": { @@ -162,7 +162,6 @@ "ircmaxell/php-yacc": "^0.0.7", "phpunit/phpunit": "^9.0" }, - "default-branch": true, "bin": [ "bin/php-parse" ], @@ -193,9 +192,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/master" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.1" }, - "time": "2024-06-03T06:24:19+00:00" + "time": "2024-10-08T18:51:32+00:00" }, { "name": "phar-io/manifest", @@ -322,31 +321,31 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "3352293d9e91513d5508c415835014881b420218" + "reference": "0448d60087a382392a1b2a1abe434466e03dcc87" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/3352293d9e91513d5508c415835014881b420218", - "reference": "3352293d9e91513d5508c415835014881b420218", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/0448d60087a382392a1b2a1abe434466e03dcc87", + "reference": "0448d60087a382392a1b2a1abe434466e03dcc87", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.18 || ^5.0", + "nikic/php-parser": "^4.19.1 || ^5.1.0", "php": ">=7.3", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-text-template": "^2.0.2", - "sebastian/code-unit-reverse-lookup": "^2.0.2", - "sebastian/complexity": "^2.0", - "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0.3", - "sebastian/version": "^3.0.1", - "theseer/tokenizer": "^1.2.0" + "phpunit/php-file-iterator": "^3.0.6", + "phpunit/php-text-template": "^2.0.4", + "sebastian/code-unit-reverse-lookup": "^2.0.3", + "sebastian/complexity": "^2.0.3", + "sebastian/environment": "^5.1.5", + "sebastian/lines-of-code": "^1.0.4", + "sebastian/version": "^3.0.2", + "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^9.6" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -355,7 +354,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.2-dev" + "dev-main": "9.2.x-dev" } }, "autoload": { @@ -392,7 +391,7 @@ "type": "github" } ], - "time": "2024-03-22T05:16:32+00:00" + "time": "2024-10-31T05:58:25+00:00" }, { "name": "phpunit/php-file-iterator", @@ -641,41 +640,41 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "feb499300d9595ea4587e7448ea990263bc47c10" + "reference": "7e5a1cc50d52a8019af1d0bf90f0980f16ea9f8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/feb499300d9595ea4587e7448ea990263bc47c10", - "reference": "feb499300d9595ea4587e7448ea990263bc47c10", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/7e5a1cc50d52a8019af1d0bf90f0980f16ea9f8a", + "reference": "7e5a1cc50d52a8019af1d0bf90f0980f16ea9f8a", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1 || ^2", + "doctrine/instantiator": "^1.5.0 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", + "myclabs/deep-copy": "^1.12.0", + "phar-io/manifest": "^2.0.4", + "phar-io/version": "^3.2.1", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.28", - "phpunit/php-file-iterator": "^3.0.5", + "phpunit/php-code-coverage": "^9.2.32", + "phpunit/php-file-iterator": "^3.0.6", "phpunit/php-invoker": "^3.1.1", - "phpunit/php-text-template": "^2.0.3", - "phpunit/php-timer": "^5.0.2", - "sebastian/cli-parser": "^1.0.1", - "sebastian/code-unit": "^1.0.6", + "phpunit/php-text-template": "^2.0.4", + "phpunit/php-timer": "^5.0.3", + "sebastian/cli-parser": "^1.0.2", + "sebastian/code-unit": "^1.0.8", "sebastian/comparator": "^4.0.8", - "sebastian/diff": "^4.0.3", - "sebastian/environment": "^5.1.3", - "sebastian/exporter": "^4.0.5", - "sebastian/global-state": "^5.0.1", - "sebastian/object-enumerator": "^4.0.3", - "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^3.2", + "sebastian/diff": "^4.0.6", + "sebastian/environment": "^5.1.5", + "sebastian/exporter": "^4.0.6", + "sebastian/global-state": "^5.0.7", + "sebastian/object-enumerator": "^4.0.4", + "sebastian/resource-operations": "^3.0.4", + "sebastian/type": "^3.2.1", "sebastian/version": "^3.0.2" }, "suggest": { @@ -736,7 +735,7 @@ "type": "tidelift" } ], - "time": "2024-06-07T04:40:16+00:00" + "time": "2024-10-31T05:51:17+00:00" }, { "name": "sebastian/cli-parser", diff --git a/src/Attributes/SchemaDocumentChildField.php b/src/Attributes/SchemaDocumentChildField.php new file mode 100644 index 0000000..7c0aa7f --- /dev/null +++ b/src/Attributes/SchemaDocumentChildField.php @@ -0,0 +1,24 @@ +Comment = $Comment; + $this->ValidSchemas = $ValidSchemas; + parent::__construct(new Name("SchemaDocumentChildField"), [], []); + } + +} diff --git a/src/Attributes/SchemaDocumentField.php b/src/Attributes/SchemaDocumentField.php index 2f108aa..16c3b3d 100644 --- a/src/Attributes/SchemaDocumentField.php +++ b/src/Attributes/SchemaDocumentField.php @@ -25,6 +25,7 @@ class SchemaDocumentField extends Attribute array $ValidSchemas = [], int $MaxSize = 0, string $MimeType = "", + SchemaDocumentChildField $Child = null ) { $this->Existence = $Existence; diff --git a/src/SchemaBuilder/SchemaBuilder.php b/src/SchemaBuilder/SchemaBuilder.php index e158235..33d8258 100644 --- a/src/SchemaBuilder/SchemaBuilder.php +++ b/src/SchemaBuilder/SchemaBuilder.php @@ -93,20 +93,18 @@ class SchemaBuilder if($key == "Name") { $propertyName = $value; - continue; } - if($key == "ValidSchemas") + elseif($key == "Child") { - foreach($value as $validSchema) - { - $temp = explode(separator: "\\", string: $validSchema); - $propertySchema["@ValidSchemas"] = "http://localhost/Schemas/V2/" . $temp[array_key_last(array: $temp)] . ".json"; - } - continue; + $propertySchema["#"] = [ + "@comment" => $value->Comment, + "@valid_schemas" => $value->ValidSchemas, + ]; } - - if(self::VerifyField($key, $value, $validKeys[1])) + elseif(self::VerifyField($key, $value, $validKeys[1])) + { $propertySchema["@" . self::PascalCaseToSnakeCase(input: $key)] = $value; + } } } if($propertyName == "")