-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathValidableBlock.php
More file actions
40 lines (34 loc) · 911 Bytes
/
ValidableBlock.php
File metadata and controls
40 lines (34 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace HiFolks\DataType\Traits;
use Swaggest\JsonSchema\Schema;
trait ValidableBlock
{
public function validateJsonViaUrl(string $url): bool
{
try {
$schema = Schema::import($url);
$schema->in($this->toJsonObject());
} catch (\Exception) {
return false;
}
return true;
}
public function validateJsonSchemaGithubWorkflow(): bool
{
return $this->validateJsonViaUrl(
"https://json.schemastore.org/github-workflow",
);
}
public function validateJsonWithSchema(string $schemaJson): bool
{
try {
$schema = Schema::import(json_decode($schemaJson));
$schema->in($this->toJsonObject());
} catch (\Exception) {
//echo $e->getMessage();
return false;
}
return true;
}
}