3 declare(strict_types=1);
88 string $description = null
103 $stability !== self::STABILITY_CONFIG
104 && $stability !== self::STABILITY_STABLE
105 && $stability !== self::STABILITY_VOLATILE
106 && !($stability === self::STABILITY_MIXED && $type === self::TYPE_COLLECTION)
108 throw new \InvalidArgumentException(
109 "Invalid stability for metric: $stability" 117 $type !== self::TYPE_BOOL
118 && $type !== self::TYPE_COUNTER
119 && $type !== self::TYPE_GAUGE
120 && $type !== self::TYPE_TIMESTAMP
121 && $type !== self::TYPE_TEXT
122 && $type !== self::TYPE_COLLECTION
124 throw new \InvalidArgumentException(
125 "Invalid type for metric: $type" 133 ($type === self::TYPE_BOOL && !is_bool(
$value))
134 || ($type === self::TYPE_COUNTER && !is_int(
$value))
135 || ($type === self::TYPE_GAUGE && !(is_int(
$value) || is_float(
$value)))
137 || ($type === self::TYPE_TEXT && !is_string(
$value))
138 || ($type === self::TYPE_COLLECTION && !is_array(
$value))
140 throw new \InvalidArgumentException(
141 "Invalid type " . gettype(
$value) .
" for metric of type $type" 145 if ($type === self::TYPE_COLLECTION) {
147 if (!($v instanceof
Metric)) {
148 throw new \InvalidArgumentException(
149 "Every element of a collection needs to be a metric, found " . gettype($v)
179 public function toYAML(
int $indentation = 0): string
183 case self::TYPE_BOOL:
190 case self::TYPE_COUNTER:
192 case self::TYPE_GAUGE:
196 return sprintf(
"%.03f",
$value);
197 case self::TYPE_TIMESTAMP:
198 return $value->format(\DateTimeInterface::ISO8601);
199 case self::TYPE_TEXT:
200 if (substr_count(
$value,
"\n") > 0) {
201 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
204 case self::TYPE_COLLECTION:
208 function (
string $k,
Metric $v) use ($indentation):
string {
209 if ($v->
getType() === self::TYPE_COLLECTION) {
221 throw new \LogicException(
"Unknown type: " . $this->
getType());
230 case self::TYPE_BOOL:
237 case self::TYPE_COUNTER:
239 case self::TYPE_GAUGE:
243 return sprintf(
"%.03f",
$value);
244 case self::TYPE_TIMESTAMP:
245 return $value->format(\DateTimeInterface::ISO8601);
246 case self::TYPE_TEXT:
247 if (substr_count(
$value,
"\n") > 0) {
248 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
251 case self::TYPE_COLLECTION:
254 $result[
$key] = $val->toArray($indentation + 1);
258 throw new \LogicException(
"Unknown type: " . $this->
getType());
265 while ($indentation--) {
279 if ($stability === self::STABILITY_MIXED) {
280 throw new \LogicException(
"Can not extract by mixed.");
284 return [$this, null];
286 if ($this->
getType() !== self::TYPE_COLLECTION) {
287 return [null, $this];
294 foreach ($values as $k => $v) {
295 list(
$e, $r) = $v->extractByStability($stability);
304 if ($extracted !== []) {
307 self::TYPE_COLLECTION,
318 self::TYPE_COLLECTION,
326 return [$extracted,
$rest];
332 $sub = $f->panel()->sub(
"", $f->legacy(
"<pre>" . $yaml .
"</pre>"));
333 return $f->panel()->report($name, [$sub]);
extractByStability(string $stability)
The extracted part will be the first entry of the array, the second will be the rest of the metrics...
toArray(int $indentation=0)
checkStability(string $stability, string $type)
const TYPE_BOOL
The type of the metric tells what to expect of the values.
A metric is something we can measure about the system.
This describes how a Report could be modified during construction of UI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkValue($type, $value)
toYAML(int $indentation=0)
toUIReport(Factory $f, string $name)
__construct(string $stability, string $type, $value, string $description=null)
getIndentation(int $indentation=0)
const STABILITY_CONFIG
The stability of a metric tells how often we expect changes in the metric.