From b8356748855d2f350358447b7ba55cb22192cfbe Mon Sep 17 00:00:00 2001 From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> Date: Fri, 17 May 2024 13:52:42 +0200 Subject: [PATCH] add workaround for API change in BlockType, fixes #250 --- lib/TestBlock.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/TestBlock.php b/lib/TestBlock.php index bacece4..031f5f1 100644 --- a/lib/TestBlock.php +++ b/lib/TestBlock.php @@ -12,8 +12,29 @@ use Courseware\BlockTypes\BlockType; use Opis\JsonSchema\Schema; +// use old API with Stud.IP < 6.0 +if (class_exists('Opis\JsonSchema\Schema')) { + trait VipsJsonSchema + { + public static function getJsonSchema(): Schema + { + return Schema::fromJsonString(self::_getJsonSchema()); + } + } +} else { + trait VipsJsonSchema + { + public static function getJsonSchema(): string + { + return self::_getJsonSchema(); + } + } +} + class TestBlock extends BlockType { + use VipsJsonSchema; + /** * Get a short string describing this type of block. */ @@ -49,7 +70,7 @@ class TestBlock extends BlockType /** * Get the JSON schema for the payload of this block type. */ - public static function getJsonSchema(): Schema + public static function _getJsonSchema(): string { $schema = [ 'type' => 'object', @@ -60,7 +81,7 @@ class TestBlock extends BlockType ] ]; - return Schema::fromJsonString(json_encode($schema)); + return json_encode($schema); } /** -- GitLab