From a8a031843d34937264f7b631e88d21401041abe8 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Thu, 16 May 2024 08:22:10 +0000 Subject: [PATCH] update opis/json-schema to 2.3.0, fixes #4173 Closes #4173 Merge request studip/studip!3011 --- RELEASE-NOTES.md | 3 + composer.json | 2 +- composer.lock | 159 ++++++++++++++++-- lib/models/Courseware/BlockTypes/Audio.php | 7 +- .../Courseware/BlockTypes/BeforeAfter.php | 7 +- .../BlockTypes/BiographyAchievements.php | 7 +- .../Courseware/BlockTypes/BiographyCareer.php | 6 +- .../Courseware/BlockTypes/BiographyGoals.php | 6 +- .../BiographyPersonalInformation.php | 6 +- .../Courseware/BlockTypes/BlockType.php | 9 +- lib/models/Courseware/BlockTypes/Canvas.php | 6 +- lib/models/Courseware/BlockTypes/Chart.php | 6 +- lib/models/Courseware/BlockTypes/Code.php | 6 +- lib/models/Courseware/BlockTypes/Confirm.php | 6 +- lib/models/Courseware/BlockTypes/Date.php | 6 +- .../Courseware/BlockTypes/DialogCards.php | 6 +- lib/models/Courseware/BlockTypes/Document.php | 7 +- lib/models/Courseware/BlockTypes/Download.php | 6 +- lib/models/Courseware/BlockTypes/Embed.php | 7 +- lib/models/Courseware/BlockTypes/Error.php | 6 +- lib/models/Courseware/BlockTypes/Folder.php | 7 +- lib/models/Courseware/BlockTypes/Gallery.php | 6 +- lib/models/Courseware/BlockTypes/Headline.php | 11 +- lib/models/Courseware/BlockTypes/IFrame.php | 7 +- lib/models/Courseware/BlockTypes/ImageMap.php | 6 +- lib/models/Courseware/BlockTypes/KeyPoint.php | 6 +- lib/models/Courseware/BlockTypes/Link.php | 7 +- lib/models/Courseware/BlockTypes/Lti.php | 7 +- .../Courseware/BlockTypes/TableOfContents.php | 6 +- lib/models/Courseware/BlockTypes/Text.php | 6 +- lib/models/Courseware/BlockTypes/Timeline.php | 7 +- .../Courseware/BlockTypes/Typewriter.php | 6 +- lib/models/Courseware/BlockTypes/Video.php | 7 +- .../ContainerTypes/AccordionContainer.php | 6 +- .../ContainerTypes/ContainerType.php | 9 +- .../ContainerTypes/ListContainer.php | 7 +- .../ContainerTypes/TabsContainer.php | 7 +- 37 files changed, 216 insertions(+), 176 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index e4b3b5be207..d262513a05f 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -29,6 +29,9 @@ - Im Rahmen von [Issue #4118](https://gitlab.studip.de/studip/studip/-/issues/4118) wurde `write_excel` ausgebaut. Als Alternative kann `phpoffice/phpspreadsheet` verwendet werden. - Im Rahmen von [TIC #3701](https://gitlab.studip.de/studip/studip/-/issues/3701) wurden die Klassen für den Cache umbenannt. Alle Vorkommnisse sollten ersetzt werden: - `StudipCacheFactory` -> `Studip\Cache\Factory` +- Die Bibliothek `opis/json-schema` wurde auf Version 2.3.0 aktualisiert ([Issue #4173](https://gitlab.studip.de/studip/studip/-/issues/4173)). Dadurch ergeben sich die folgenden Änderungen für Komponenten aus Courseware (siehe auch [Migration Guide](https://opis.io/json-schema/2.x/php-migration.html#validator)): + - Instanzen von `Courseware\ContainerTypes\BlockType` müssen die Methode `getJsonSchema` anpassen. Der Return Type ist nun `string` und es muss der Inhalt der Schema-Datei zurückgegeben werden ohne Aufruf von `Schema::fromJsonString()`. + - Instanzen von `Courseware\ContainerTypes\ContainerType` müssen die Methode `getJsonSchema` anpassen. Der Return Type ist nun `string` und es muss der Inhalt der Schema-Datei zurückgegeben werden ohne Aufruf von `Schema::fromJsonString()`. ## Security related issues diff --git a/composer.json b/composer.json index abfff34758a..ac010e5ea8d 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "ext-pdo": "*", "ext-mbstring": "*", "ext-dom": "*", - "opis/json-schema": "^1.0", + "opis/json-schema": "2.3.0", "slim/psr7": "1.6.1", "slim/slim": "4.13.0", "php-di/php-di": "7.0.0", diff --git a/composer.lock b/composer.lock index f82debe1b70..c2d073c3ce8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e56f52fb79feb267575817504f36ad7c", + "content-hash": "ce45f97b00f8fa90b09d0b907b3a4f53", "packages": [ { "name": "algo26-matthias/idna-convert", @@ -1823,36 +1823,33 @@ }, { "name": "opis/json-schema", - "version": "1.1.0", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/opis/json-schema.git", - "reference": "39d8072be8657a329a284339994401066406c43b" + "reference": "c48df6d7089a45f01e1c82432348f2d5976f9bfb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opis/json-schema/zipball/39d8072be8657a329a284339994401066406c43b", - "reference": "39d8072be8657a329a284339994401066406c43b", + "url": "https://api.github.com/repos/opis/json-schema/zipball/c48df6d7089a45f01e1c82432348f2d5976f9bfb", + "reference": "c48df6d7089a45f01e1c82432348f2d5976f9bfb", "shasum": "" }, "require": { - "php": ">=7.0" + "ext-json": "*", + "opis/string": "^2.0", + "opis/uri": "^1.0", + "php": "^7.4 || ^8.0" }, "require-dev": { "ext-bcmath": "*", "ext-intl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "opis/string": "^1.4", - "phpunit/phpunit": "^6.5 || ^7.0 || ^9.4" - }, - "suggest": { - "opis/string": "A standalone library for manipulating multibyte strings" + "phpunit/phpunit": "^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { @@ -1874,19 +1871,145 @@ "email": "marius.sarca@gmail.com" } ], - "description": "Json Schema Validator", - "homepage": "http://www.opis.io/json-schema", + "description": "Json Schema Validator for PHP", + "homepage": "https://opis.io/json-schema", "keywords": [ "json", + "json-schema", "schema", "validation", "validator" ], "support": { "issues": "https://github.com/opis/json-schema/issues", - "source": "https://github.com/opis/json-schema/tree/1.1.0" + "source": "https://github.com/opis/json-schema/tree/2.3.0" + }, + "time": "2022-01-08T20:38:03+00:00" + }, + { + "name": "opis/string", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/opis/string.git", + "reference": "9ebf1a1f873f502f6859d11210b25a4bf5d141e7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/opis/string/zipball/9ebf1a1f873f502f6859d11210b25a4bf5d141e7", + "reference": "9ebf1a1f873f502f6859d11210b25a4bf5d141e7", + "shasum": "" + }, + "require": { + "ext-iconv": "*", + "ext-json": "*", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Opis\\String\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Marius Sarca", + "email": "marius.sarca@gmail.com" + }, + { + "name": "Sorin Sarca", + "email": "sarca_sorin@hotmail.com" + } + ], + "description": "Multibyte strings as objects", + "homepage": "https://opis.io/string", + "keywords": [ + "multi-byte", + "opis", + "string", + "string manipulation", + "utf-8" + ], + "support": { + "issues": "https://github.com/opis/string/issues", + "source": "https://github.com/opis/string/tree/2.0.1" + }, + "time": "2022-01-14T15:42:23+00:00" + }, + { + "name": "opis/uri", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/opis/uri.git", + "reference": "0f3ca49ab1a5e4a6681c286e0b2cc081b93a7d5a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/opis/uri/zipball/0f3ca49ab1a5e4a6681c286e0b2cc081b93a7d5a", + "reference": "0f3ca49ab1a5e4a6681c286e0b2cc081b93a7d5a", + "shasum": "" + }, + "require": { + "opis/string": "^2.0", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Opis\\Uri\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Marius Sarca", + "email": "marius.sarca@gmail.com" + }, + { + "name": "Sorin Sarca", + "email": "sarca_sorin@hotmail.com" + } + ], + "description": "Build, parse and validate URIs and URI-templates", + "homepage": "https://opis.io", + "keywords": [ + "URI Template", + "parse url", + "punycode", + "uri", + "uri components", + "url", + "validate uri" + ], + "support": { + "issues": "https://github.com/opis/uri/issues", + "source": "https://github.com/opis/uri/tree/1.1.0" }, - "time": "2021-04-14T20:02:50+00:00" + "time": "2021-05-22T15:57:08+00:00" }, { "name": "paragonie/constant_time_encoding", diff --git a/lib/models/Courseware/BlockTypes/Audio.php b/lib/models/Courseware/BlockTypes/Audio.php index dd2588a1e5e..22dc16710d3 100644 --- a/lib/models/Courseware/BlockTypes/Audio.php +++ b/lib/models/Courseware/BlockTypes/Audio.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware audio block. * @@ -42,11 +40,10 @@ class Audio extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Audio.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } /** diff --git a/lib/models/Courseware/BlockTypes/BeforeAfter.php b/lib/models/Courseware/BlockTypes/BeforeAfter.php index b4f33ca9c08..e174bff2d09 100644 --- a/lib/models/Courseware/BlockTypes/BeforeAfter.php +++ b/lib/models/Courseware/BlockTypes/BeforeAfter.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware before after block. * @@ -41,11 +39,10 @@ class BeforeAfter extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/BeforeAfter.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } /** diff --git a/lib/models/Courseware/BlockTypes/BiographyAchievements.php b/lib/models/Courseware/BlockTypes/BiographyAchievements.php index 3af5d64daee..2f8aeb7a000 100644 --- a/lib/models/Courseware/BlockTypes/BiographyAchievements.php +++ b/lib/models/Courseware/BlockTypes/BiographyAchievements.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware biography achievements block. * @@ -57,11 +55,10 @@ class BiographyAchievements extends BlockType parent::setPayload($payload); } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/BiographyAchievements.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/BiographyCareer.php b/lib/models/Courseware/BlockTypes/BiographyCareer.php index ebd1a858a97..9425cfed405 100644 --- a/lib/models/Courseware/BlockTypes/BiographyCareer.php +++ b/lib/models/Courseware/BlockTypes/BiographyCareer.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware biography career block. * @@ -48,11 +46,11 @@ class BiographyCareer extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/BiographyCareer.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/BiographyGoals.php b/lib/models/Courseware/BlockTypes/BiographyGoals.php index dcfb76cc961..b4f1b644299 100644 --- a/lib/models/Courseware/BlockTypes/BiographyGoals.php +++ b/lib/models/Courseware/BlockTypes/BiographyGoals.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware biography personal goals block. * @@ -53,11 +51,11 @@ class BiographyGoals extends BlockType parent::setPayload($payload); } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/BiographyGoals.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/BiographyPersonalInformation.php b/lib/models/Courseware/BlockTypes/BiographyPersonalInformation.php index 8f3c0c16d4e..bb11f530a37 100644 --- a/lib/models/Courseware/BlockTypes/BiographyPersonalInformation.php +++ b/lib/models/Courseware/BlockTypes/BiographyPersonalInformation.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware biography personal information block. * @@ -41,11 +39,11 @@ class BiographyPersonalInformation extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/BiographyPersonalInformation.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/BlockType.php b/lib/models/Courseware/BlockTypes/BlockType.php index b3d5abfba7f..b87a219fbad 100644 --- a/lib/models/Courseware/BlockTypes/BlockType.php +++ b/lib/models/Courseware/BlockTypes/BlockType.php @@ -3,7 +3,6 @@ namespace Courseware\BlockTypes; use Courseware\CoursewarePlugin; -use Opis\JsonSchema\Schema; use Opis\JsonSchema\Validator; /** @@ -52,9 +51,9 @@ abstract class BlockType * Returns the JSON schema which is used to validate the payload of * instances of this type of block. * - * @return Schema the JSON schema to be used + * @return string the JSON schema to be used */ - abstract public static function getJsonSchema(): Schema; + abstract public static function getJsonSchema(): string; /** * Returns a list of categories to which this type of block is associated. @@ -192,10 +191,8 @@ abstract class BlockType */ public function validatePayload($payload): bool { - $schema = static::getJsonSchema(); $validator = new Validator(); - $result = $validator->schemaValidation($payload, $schema); - + $result = $validator->validate($payload, static::getJsonSchema()); return $result->isValid(); } diff --git a/lib/models/Courseware/BlockTypes/Canvas.php b/lib/models/Courseware/BlockTypes/Canvas.php index e7b14e99665..cc2196accd7 100644 --- a/lib/models/Courseware/BlockTypes/Canvas.php +++ b/lib/models/Courseware/BlockTypes/Canvas.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware canvas block. * @@ -40,11 +38,11 @@ class Canvas extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Canvas.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } /** diff --git a/lib/models/Courseware/BlockTypes/Chart.php b/lib/models/Courseware/BlockTypes/Chart.php index 196e90ff0fb..147c3c51459 100644 --- a/lib/models/Courseware/BlockTypes/Chart.php +++ b/lib/models/Courseware/BlockTypes/Chart.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware chart block. * @@ -38,11 +36,11 @@ class Chart extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Chart.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Code.php b/lib/models/Courseware/BlockTypes/Code.php index 5b1454cd824..d5bd1c52b91 100644 --- a/lib/models/Courseware/BlockTypes/Code.php +++ b/lib/models/Courseware/BlockTypes/Code.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware code block. * @@ -37,11 +35,11 @@ class Code extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Code.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Confirm.php b/lib/models/Courseware/BlockTypes/Confirm.php index bb6738d5f74..2c25316ee48 100644 --- a/lib/models/Courseware/BlockTypes/Confirm.php +++ b/lib/models/Courseware/BlockTypes/Confirm.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware confirm block. * @@ -36,11 +34,11 @@ class Confirm extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Confirm.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Date.php b/lib/models/Courseware/BlockTypes/Date.php index 46e77d85ea3..548e648da23 100644 --- a/lib/models/Courseware/BlockTypes/Date.php +++ b/lib/models/Courseware/BlockTypes/Date.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware date block. * @@ -37,11 +35,11 @@ class Date extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Date.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/DialogCards.php b/lib/models/Courseware/BlockTypes/DialogCards.php index 74b843cbe26..875a0b3c30d 100644 --- a/lib/models/Courseware/BlockTypes/DialogCards.php +++ b/lib/models/Courseware/BlockTypes/DialogCards.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware dialog cards block. * @@ -96,11 +94,11 @@ class DialogCards extends BlockType return $payload; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/DialogCards.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Document.php b/lib/models/Courseware/BlockTypes/Document.php index db1ba6ee179..562ec08da2a 100644 --- a/lib/models/Courseware/BlockTypes/Document.php +++ b/lib/models/Courseware/BlockTypes/Document.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware document block. * @@ -39,11 +37,10 @@ class Document extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Document.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } /** diff --git a/lib/models/Courseware/BlockTypes/Download.php b/lib/models/Courseware/BlockTypes/Download.php index d736009d181..e7bb65c2035 100644 --- a/lib/models/Courseware/BlockTypes/Download.php +++ b/lib/models/Courseware/BlockTypes/Download.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware download block. * @@ -72,11 +70,11 @@ class Download extends BlockType return $payload; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Download.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Embed.php b/lib/models/Courseware/BlockTypes/Embed.php index cb997ee0239..1b366241225 100644 --- a/lib/models/Courseware/BlockTypes/Embed.php +++ b/lib/models/Courseware/BlockTypes/Embed.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware embed block. * @@ -40,11 +38,10 @@ class Embed extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Embed.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public function getPayload() diff --git a/lib/models/Courseware/BlockTypes/Error.php b/lib/models/Courseware/BlockTypes/Error.php index 2e154562383..3f290b1ce07 100644 --- a/lib/models/Courseware/BlockTypes/Error.php +++ b/lib/models/Courseware/BlockTypes/Error.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware error block. * @@ -34,11 +32,11 @@ class Error extends BlockType return []; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Error.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Folder.php b/lib/models/Courseware/BlockTypes/Folder.php index a3ea7d96f20..9f186dfd092 100644 --- a/lib/models/Courseware/BlockTypes/Folder.php +++ b/lib/models/Courseware/BlockTypes/Folder.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware folder block. * @@ -116,11 +114,10 @@ class Folder extends BlockType return $payload; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Folder.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Gallery.php b/lib/models/Courseware/BlockTypes/Gallery.php index 5f9bb0b6d56..5041573d8d3 100644 --- a/lib/models/Courseware/BlockTypes/Gallery.php +++ b/lib/models/Courseware/BlockTypes/Gallery.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware gallery block. * @@ -133,11 +131,11 @@ class Gallery extends BlockType return $payload; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Gallery.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Headline.php b/lib/models/Courseware/BlockTypes/Headline.php index 0c821386b82..616af887ca3 100644 --- a/lib/models/Courseware/BlockTypes/Headline.php +++ b/lib/models/Courseware/BlockTypes/Headline.php @@ -2,7 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; use Opis\JsonSchema\Validator; /** @@ -49,11 +48,10 @@ class Headline extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Headline.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } /** @@ -88,11 +86,8 @@ class Headline extends BlockType public function validatePayload($payload): bool { unset($payload->background_image); - $schema = static::getJsonSchema(); - $validator = new Validator(); - $result = $validator->schemaValidation($payload, $schema); - return $result->isValid(); + return parent::validatePayload($payload); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/IFrame.php b/lib/models/Courseware/BlockTypes/IFrame.php index 5c914f9e8fb..f697e742fbf 100644 --- a/lib/models/Courseware/BlockTypes/IFrame.php +++ b/lib/models/Courseware/BlockTypes/IFrame.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware iFrame block. * @@ -45,11 +43,10 @@ class IFrame extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/IFrame.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/ImageMap.php b/lib/models/Courseware/BlockTypes/ImageMap.php index e275c46254e..d9ad8454344 100644 --- a/lib/models/Courseware/BlockTypes/ImageMap.php +++ b/lib/models/Courseware/BlockTypes/ImageMap.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware image map block. * @@ -66,11 +64,11 @@ class ImageMap extends BlockType return $payload; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/ImageMap.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/KeyPoint.php b/lib/models/Courseware/BlockTypes/KeyPoint.php index 859970471a2..d1e6c349c8c 100644 --- a/lib/models/Courseware/BlockTypes/KeyPoint.php +++ b/lib/models/Courseware/BlockTypes/KeyPoint.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware key point block. * @@ -38,11 +36,11 @@ class KeyPoint extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/KeyPoint.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Link.php b/lib/models/Courseware/BlockTypes/Link.php index ccf9f66d368..3282e2c4bc8 100644 --- a/lib/models/Courseware/BlockTypes/Link.php +++ b/lib/models/Courseware/BlockTypes/Link.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware link block. * @@ -39,11 +37,10 @@ class Link extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Link.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Lti.php b/lib/models/Courseware/BlockTypes/Lti.php index 8b527c193df..193bfb57227 100644 --- a/lib/models/Courseware/BlockTypes/Lti.php +++ b/lib/models/Courseware/BlockTypes/Lti.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware LTI block. * @@ -44,11 +42,10 @@ class Lti extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Lti.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public function getPayload() diff --git a/lib/models/Courseware/BlockTypes/TableOfContents.php b/lib/models/Courseware/BlockTypes/TableOfContents.php index c48b6835443..f0485b9766a 100644 --- a/lib/models/Courseware/BlockTypes/TableOfContents.php +++ b/lib/models/Courseware/BlockTypes/TableOfContents.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware table of contents block. * @@ -37,11 +35,11 @@ class TableOfContents extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/TableOfContents.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Text.php b/lib/models/Courseware/BlockTypes/Text.php index b72801945e6..917efb3dfe4 100644 --- a/lib/models/Courseware/BlockTypes/Text.php +++ b/lib/models/Courseware/BlockTypes/Text.php @@ -2,7 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; require_once 'lib/classes/Markup.class.php'; /** @@ -66,11 +65,10 @@ class Text extends BlockType parent::setPayload($payload); } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Text.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } /** diff --git a/lib/models/Courseware/BlockTypes/Timeline.php b/lib/models/Courseware/BlockTypes/Timeline.php index 81802cea3ea..5647e92ca39 100644 --- a/lib/models/Courseware/BlockTypes/Timeline.php +++ b/lib/models/Courseware/BlockTypes/Timeline.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware timeline block. * @@ -45,11 +43,10 @@ class Timeline extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Timeline.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Typewriter.php b/lib/models/Courseware/BlockTypes/Typewriter.php index 2544ddee1eb..b303fb36536 100644 --- a/lib/models/Courseware/BlockTypes/Typewriter.php +++ b/lib/models/Courseware/BlockTypes/Typewriter.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware typewriter block. * @@ -39,11 +37,11 @@ class Typewriter extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Typewriter.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } public static function getCategories(): array diff --git a/lib/models/Courseware/BlockTypes/Video.php b/lib/models/Courseware/BlockTypes/Video.php index 431f69b68e6..1ad70646d2e 100644 --- a/lib/models/Courseware/BlockTypes/Video.php +++ b/lib/models/Courseware/BlockTypes/Video.php @@ -2,8 +2,6 @@ namespace Courseware\BlockTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware video block. * @@ -42,11 +40,10 @@ class Video extends BlockType ]; } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/Video.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } /** diff --git a/lib/models/Courseware/ContainerTypes/AccordionContainer.php b/lib/models/Courseware/ContainerTypes/AccordionContainer.php index 185b6d113d8..cd00a063a45 100644 --- a/lib/models/Courseware/ContainerTypes/AccordionContainer.php +++ b/lib/models/Courseware/ContainerTypes/AccordionContainer.php @@ -2,8 +2,6 @@ namespace Courseware\ContainerTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware accordion container stored in payload. * @@ -54,10 +52,10 @@ class AccordionContainer extends ContainerType $this->setPayload($payload); } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/AccordionContainer.json'; - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } } diff --git a/lib/models/Courseware/ContainerTypes/ContainerType.php b/lib/models/Courseware/ContainerTypes/ContainerType.php index a4eae29ba82..baddaabf5c0 100644 --- a/lib/models/Courseware/ContainerTypes/ContainerType.php +++ b/lib/models/Courseware/ContainerTypes/ContainerType.php @@ -3,7 +3,6 @@ namespace Courseware\ContainerTypes; use Courseware\CoursewarePlugin; -use Opis\JsonSchema\Schema; use Opis\JsonSchema\Validator; /** @@ -28,9 +27,9 @@ abstract class ContainerType * Returns the JSON schema which is used to validate the payload of * instances of this type of container. * - * @return Schema the JSON schema to be used + * @return string the JSON schema to be used */ - abstract public static function getJsonSchema(): Schema; + abstract public static function getJsonSchema(): string; /** * Returns a short string describing this type of container. @@ -150,10 +149,8 @@ abstract class ContainerType */ public function validatePayload($payload): bool { - $schema = static::getJsonSchema(); $validator = new Validator(); - $result = $validator->schemaValidation($payload, $schema); - + $result = $validator->validate($payload, static::getJsonSchema()); return $result->isValid(); } diff --git a/lib/models/Courseware/ContainerTypes/ListContainer.php b/lib/models/Courseware/ContainerTypes/ListContainer.php index b98d8a1aaf9..adbf7c3bdd7 100644 --- a/lib/models/Courseware/ContainerTypes/ListContainer.php +++ b/lib/models/Courseware/ContainerTypes/ListContainer.php @@ -2,8 +2,6 @@ namespace Courseware\ContainerTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware list container stored in payload. * @@ -50,10 +48,9 @@ class ListContainer extends ContainerType $this->setPayload($payload); } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/ListContainer.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } } diff --git a/lib/models/Courseware/ContainerTypes/TabsContainer.php b/lib/models/Courseware/ContainerTypes/TabsContainer.php index 01f3d451043..66a56b8f884 100644 --- a/lib/models/Courseware/ContainerTypes/TabsContainer.php +++ b/lib/models/Courseware/ContainerTypes/TabsContainer.php @@ -2,8 +2,6 @@ namespace Courseware\ContainerTypes; -use Opis\JsonSchema\Schema; - /** * This class represents the content of a Courseware tabs container stored in payload. * @@ -54,10 +52,9 @@ class TabsContainer extends ContainerType $this->setPayload($payload); } - public static function getJsonSchema(): Schema + public static function getJsonSchema(): string { $schemaFile = __DIR__.'/TabsContainer.json'; - - return Schema::fromJsonString(file_get_contents($schemaFile)); + return file_get_contents($schemaFile); } } -- GitLab