Newer
Older
<?php
namespace SmartDataContext\Domain;
class SmartDataContext {
static function ValidateContent($content) {
if (! $content) {
return ["content property empty"];
} else {
return [];
}
}
static function ValidateFeatures($features) {
if ($features && array_key_exists("tags", $features) && is_array($features["tags"])) {
return ["features missing tags entry or invalid (should be an array)"];
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
}
}
static function ValidateTimestamp($t0, $t1) {
if (! is_int($t0) || ! is_int($t1)) {
return ["t0 and t1 must time integer timestamps"];
} else if ($t0 > $t1 && $t1 != -1) {
return ["t1 must be equal or after t0"];
} else {
return [];
}
}
static function ValidateSmartDataSources(mixed $smartDataSources) {
if (! is_array($smartDataSources)) {
return ["smartDataSources should be an array"];
}
$result = [];
foreach ($smartDataSources as $smartDataSource) {
if (is_string($smartDataSource)) {
// TODO: Support confidence
if (! SmartDataContext::ValidSignature($smartDataSource)) {
$result[] = "$smartDataSource is an invalid signature";
}
} else if (is_array($smartDataSource)) {
if (! SmartDataContext::ValidSphere($smartDataSource)) {
$result[] = json_encode($smartDataSource) . " is an invalid sphere";
}
}
}
return $result;
}
static function ValidSignature(string $signature) {
return preg_match('/^[a-f0-9]+$/i', $signature);
}
static function ValidSphere(array $sphere) {
// TODO: Support confidence
return count(array_filter($sphere, 'is_int')) == 4;
}
static function ValidateSmartDataUnits(mixed $smartDataUnits) {
if (is_array($smartDataUnits) && count(array_filter($smartDataUnits, 'is_int')) == count($smartDataUnits)) {
return [];
} else {
return ["smartDataUnits should be a array of longs"];
}
}
}