From 02b73987adec05e1e13f8d9a5537d59f75699a68 Mon Sep 17 00:00:00 2001 From: "John R. D'Orazio" Date: Thu, 2 May 2024 09:00:09 +0200 Subject: [PATCH] add yaml validation for litcaltest server --- LitCalHealth.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/LitCalHealth.php b/LitCalHealth.php index ae2f41ae..081315e5 100644 --- a/LitCalHealth.php +++ b/LitCalHealth.php @@ -299,6 +299,37 @@ private function validateCalendar( string $Calendar, int $Year, string $category $this->sendMessage( $to, $message ); } break; + case "YAML": + try { + $yamlData = yaml_parse( $data ); + if( $yamlData ) { + $message = new stdClass(); + $message->type = "success"; + $message->text = "The $category of $Calendar for the year $Year was successfully decoded as YAML"; + $message->classes = ".calendar-$Calendar.json-valid.year-$Year"; + $this->sendMessage( $to, $message ); + + $validationResult = $this->validateDataAgainstSchema( $yamlData, LitSchema::LITCAL ); + if( gettype( $validationResult ) === 'boolean' && $validationResult === true ) { + $message = new stdClass(); + $message->type = "success"; + $message->text = "The $category of $Calendar for the year $Year was successfully validated against the Schema " . LitSchema::LITCAL; + $message->classes = ".calendar-$Calendar.schema-valid.year-$Year"; + $this->sendMessage( $to, $message ); + } + else if( gettype( $validationResult === 'object' ) ) { + $validationResult->classes = ".calendar-$Calendar.schema-valid.year-$Year"; + $this->sendMessage( $to, $validationResult ); + } + } + } catch (Exception $ex) { + $message = new stdClass(); + $message->type = "error"; + $message->text = "There was an error decoding the $category of $Calendar for the year $Year from the URL " . self::LitCalBaseUrl . $req . " as YAML: " . $ex->getMessage(); + $message->classes = ".calendar-$Calendar.json-valid.year-$Year"; + $this->sendMessage( $to, $message ); + } + break; case "JSON": default: $jsonData = json_decode( $data );