MCPcopy Create free account
hub / github.com/Rello/analytics / BundleDefinition

Class BundleDefinition

lib/Service/BundleDefinition.php:11–112  ·  view source on GitHub ↗

Portable v1 bundles contain classic stored datasets, reports and report/text Panorama tiles. */

Source from the content-addressed store, hash-verified

9
10/** Portable v1 bundles contain classic stored datasets, reports and report/text Panorama tiles. */
11class BundleDefinition {
12 public static function validate(array $bundle): void {
13 self::check(($bundle['format'] ?? null) === 'analytics-bundle' && ($bundle['version'] ?? null) === 1, 'Unsupported bundle format or version');
14 $maps = [];
15 foreach (['folders', 'datasets', 'reports', 'panoramas'] as $kind) {
16 $items = $bundle[$kind] ?? [];
17 self::check(is_array($items) && array_is_list($items) && count($items) <= 500, 'Invalid bundle collection: ' . $kind);
18 $maps[$kind] = [];
19 foreach ($items as $item) {
20 self::check(is_array($item), 'Invalid bundle object');
21 $key = $item['key'] ?? null;
22 self::check(is_string($key) && preg_match('/^[a-zA-Z][a-zA-Z0-9_-]{0,79}$/D', $key) && !isset($maps[$kind][$key]), 'Invalid or duplicate bundle key');
23 self::check(is_string($item['name'] ?? null) && trim($item['name']) !== '' && strlen($item['name']) <= 64, 'Invalid object name');
24 $maps[$kind][$key] = $item;
25 }
26 }
27 self::check(count($maps['reports']) > 0, 'A bundle needs reports');
28 foreach ($maps['folders'] as $key => $folder) {
29 self::check(in_array($folder['scope'] ?? null, ['datasets', 'reports', 'panoramas'], true), 'Invalid folder scope');
30 // v1 supports root folders only; never silently flatten a hierarchy.
31 self::check(!isset($folder['parent']), 'Nested bundle folders are not supported in version 1');
32 }
33 foreach (['datasets', 'reports', 'panoramas'] as $kind) {
34 foreach ($maps[$kind] as $item) {
35 if (isset($item['folder'])) {
36 self::check(is_string($item['folder']) && isset($maps['folders'][$item['folder']]) && $maps['folders'][$item['folder']]['scope'] === $kind, 'Unknown or incompatible folder');
37 }
38 }
39 }
40 foreach ($maps['datasets'] as $dataset) {
41 self::check(($dataset['storageMode'] ?? 'legacy') === 'legacy' && !isset($dataset['columns']) && !isset($dataset['flexible']), 'Unsupported bundle dataset storage');
42 foreach (['dimension1', 'dimension2', 'value'] as $field) self::check(is_string($dataset[$field] ?? null), 'Missing dataset column label');
43 $rows = $dataset['data'] ?? [];
44 self::check(is_array($rows) && array_is_list($rows) && count($rows) <= 100000, 'Invalid dataset rows');
45 $seen = [];
46 foreach ($rows as $row) {
47 self::check(is_array($row) && array_is_list($row) && count($row) === 3, 'A classic dataset row needs three values');
48 self::check(is_string($row[0]) && is_string($row[1]) && strlen($row[0]) <= 256 && strlen($row[1]) <= 256 && !str_contains($row[0] . $row[1], '*'), 'Invalid row dimensions');
49 self::check((is_string($row[2]) || is_int($row[2]) || is_float($row[2])) && preg_match('/^-?\d{1,13}(?:\.\d{1,2})?$/D', (string)$row[2]), 'Classic dataset values need at most two decimal places');
50 $key = json_encode([$row[0], $row[1]]);
51 self::check(!isset($seen[$key]), 'Duplicate dataset row');
52 $seen[$key] = true;
53 }
54 }
55 foreach ($maps['reports'] as $report) {
56 self::check(is_string($report['dataset'] ?? null) && isset($maps['datasets'][$report['dataset']]), 'Unknown bundle dataset');
57 self::check(!isset($report['type']) || $report['type'] === 2, 'Bundle v1 supports stored reports only');
58 self::check(!isset($report['link']) && !isset($report['dataload']), 'External sources and dataloads are not supported in bundle v1');
59 self::check(in_array($report['visualization'] ?? null, ['table', 'chart', 'ct'], true), 'Invalid visualization');
60 self::check(is_string($report['chart'] ?? null) && in_array($report['chart'], ['', 'column', 'columnSt', 'columnSt100', 'line', 'datetime', 'area', 'doughnut', 'funnel'], true), 'Invalid chart');
61 self::check(!isset($report['subheader']) || is_string($report['subheader']), 'Invalid report subtitle');
62 foreach (['chartoptions', 'dataoptions', 'filteroptions', 'tableoptions'] as $field) self::check(!isset($report[$field]) || is_array($report[$field]), 'Bundle report options must be JSON objects or arrays');
63 $thresholds = $report['thresholds'] ?? [];
64 self::check(is_array($thresholds) && array_is_list($thresholds), 'Invalid thresholds');
65 foreach ($thresholds as $threshold) {
66 self::check(is_array($threshold) && is_int($threshold['dimension'] ?? null) && $threshold['dimension'] >= 0 && $threshold['dimension'] <= 100, 'Invalid threshold dimension');
67 self::check(in_array($threshold['severity'] ?? null, [2, 3, 4], true) && in_array($threshold['coloring'] ?? null, ['value', 'row'], true), 'Only display thresholds are supported');
68 self::check(in_array($threshold['option'] ?? null, ['EQ', 'NE', 'GT', 'LT', 'GE', 'LE', '=', '!=', '>', '<', '>=', '<='], true) && is_numeric($threshold['value'] ?? null), 'Invalid threshold comparison');

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected