Skip to content

Commit

Permalink
prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRDOrazio committed Jun 6, 2022
1 parent 2acc197 commit a52019e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 63 deletions.
95 changes: 43 additions & 52 deletions LitCalHealth.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,76 +108,67 @@ public function __construct() {
}

private function executeValidation( object $validation, ConnectionInterface $to ) {
//if( file_exists( $validation->sourceFile ) ) {
$dataPath = $validation->sourceFile;
switch( $validation->category ) {
case 'universalcalendar':
$schema = LitCalHealth::DataPathToSchema[ $dataPath ];
break;
case 'nationalcalendar':
$schema = LitSchema::NATIONAL;
break;
case 'diocesancalendar':
$schema = LitSchema::DIOCESAN;
break;
case 'widerregioncalendar':
$schema = LitSchema::WIDERREGION;
break;
case 'propriumdesanctis':
$schema = LitSchema::PROPRIUMDESANCTIS;
break;
}
$data = file_get_contents( $dataPath );
if( $data !== false ) {
$dataPath = $validation->sourceFile;
switch( $validation->category ) {
case 'universalcalendar':
$schema = LitCalHealth::DataPathToSchema[ $dataPath ];
break;
case 'nationalcalendar':
$schema = LitSchema::NATIONAL;
break;
case 'diocesancalendar':
$schema = LitSchema::DIOCESAN;
break;
case 'widerregioncalendar':
$schema = LitSchema::WIDERREGION;
break;
case 'propriumdesanctis':
$schema = LitSchema::PROPRIUMDESANCTIS;
break;
}
$data = file_get_contents( $dataPath );
if( $data !== false ) {
$message = new stdClass();
$message->type = "success";
$message->text = "The Data file $dataPath exists";
$message->classes = ".$validation->validate.file-exists";
$this->sendMessage( $to, $message );

$jsonData = json_decode( $data );
if( json_last_error() === JSON_ERROR_NONE ) {
$message = new stdClass();
$message->type = "success";
$message->text = "The Data file $dataPath exists";
$message->classes = ".$validation->validate.file-exists";
$message->text = "The Data file $dataPath was successfully decoded as JSON";
$message->classes = ".$validation->validate.json-valid";
$this->sendMessage( $to, $message );

$jsonData = json_decode( $data );
if( json_last_error() === JSON_ERROR_NONE ) {
$validationResult = $this->validateDataAgainstSchema( $jsonData, $schema );
if( gettype( $validationResult ) === 'boolean' && $validationResult === true ) {
$message = new stdClass();
$message->type = "success";
$message->text = "The Data file $dataPath was successfully decoded as JSON";
$message->classes = ".$validation->validate.json-valid";
$this->sendMessage( $to, $message );

$validationResult = $this->validateDataAgainstSchema( $jsonData, $schema );
if( gettype( $validationResult ) === 'boolean' && $validationResult === true ) {
$message = new stdClass();
$message->type = "success";
$message->text = "The Data file $dataPath was successfully validated against the Schema $schema";
$message->classes = ".$validation->validate.schema-valid";
$this->sendMessage( $to, $message );
}
else if( gettype( $validationResult === 'object' ) ) {
$validationResult->classes = ".$validation->validate.schema-valid";
$this->sendMessage( $to, $validationResult );
}
} else {
$message = new stdClass();
$message->type = "error";
$message->text = "There was an error decoding the Data file $dataPath as JSON: " . json_last_error_msg();
$message->classes = ".$validation->validate.json-valid";
$message->text = "The Data file $dataPath was successfully validated against the Schema $schema";
$message->classes = ".$validation->validate.schema-valid";
$this->sendMessage( $to, $message );
}

else if( gettype( $validationResult === 'object' ) ) {
$validationResult->classes = ".$validation->validate.schema-valid";
$this->sendMessage( $to, $validationResult );
}
} else {
$message = new stdClass();
$message->type = "error";
$message->text = "Data file $dataPath does not exist";
$message->classes = ".$validation->validate.file-exists";
$message->text = "There was an error decoding the Data file $dataPath as JSON: " . json_last_error_msg();
$message->classes = ".$validation->validate.json-valid";
$this->sendMessage( $to, $message );
}
/*

} else {
$message = new stdClass();
$message->type = "error";
$message->text = "The validation requested \"{$validation->validate}\" does not seem to be a supported validation, or the corresponding file to validate \"{$validation->sourceFile} does not exist\"";
$message->text = "Data file $dataPath does not exist";
$message->classes = ".$validation->validate.file-exists";
$this->sendMessage( $to, $message );
}
*/
}

private function validateCalendar( string $Calendar, int $Year, string $category, ConnectionInterface $to ) : void {
Expand Down
22 changes: 11 additions & 11 deletions LitCalTestServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;

include_once( 'LitCalHealth.php' );
include_once( 'vendor/autoload.php' );
include_once( 'LitCalHealth.php' );
include_once( 'vendor/autoload.php' );

$server = IoServer::factory(
new HttpServer(
new WsServer(
new LitCalHealth()
)
),
8080
);
$server = IoServer::factory(
new HttpServer(
new WsServer(
new LitCalHealth()
)
),
8080
);

$server->run();
$server->run();

0 comments on commit a52019e

Please sign in to comment.