ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ArrayStorage.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
23 class ArrayStorage implements Storage
24 {
26 
30  protected array $metrics;
31 
32  public function __construct()
33  {
34  $this->metrics = [];
35  }
36 
40  public function store(string $key, Metric $metric): void
41  {
42  $path = explode(".", $key);
43  $this->metrics = $this->doStore($this->metrics, $path, $metric);
44  }
45 
49  protected function doStore(array $base, array $path, $metric): array
50  {
51  $key = array_shift($path);
52  if (count($path) == 0) {
53  $base[$key] = $metric;
54  return $base;
55  }
56 
57  $base[$key] = $this->doStore($base[$key] ?? [], $path, $metric);
58  return $base;
59  }
60 
61  public function get(): array
62  {
63  return $this->metrics;
64  }
65 
66  public function asMetric(): Metric
67  {
68  return $this->doAsMetric($this->metrics);
69  }
70 
71  protected function doAsMetric(array $cur): Metric
72  {
73  return new Metric(
76  array_map(
77  function ($v) {
78  if (is_array($v)) {
79  return $this->doAsMetric($v);
80  }
81  return $v;
82  },
83  $cur
84  )
85  );
86  }
87 }
trait StorageConvenience
Implements the convenience methods of Storage over Storage::store.
doStore(array $base, array $path, $metric)
Recursive implementation of storing.
$path
Definition: ltiservices.php:32
A metric is something we can measure about the system.
Definition: Metric.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
store(string $key, Metric $metric)
$base
Definition: index.php:4