<?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 []; } else { return ["features missing tags entry or invalid (should be an array)"]; } } 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"]; } } }