92 && !(
$stability === self::STABILITY_MIXED &&
$type === self::TYPE_COLLECTION)
94 throw new \InvalidArgumentException(
95 "Invalid stability for metric: $stability"
103 $type !== self::TYPE_BOOL
104 &&
$type !== self::TYPE_COUNTER
105 &&
$type !== self::TYPE_GAUGE
106 &&
$type !== self::TYPE_TIMESTAMP
107 &&
$type !== self::TYPE_TEXT
108 &&
$type !== self::TYPE_COLLECTION
110 throw new \InvalidArgumentException(
111 "Invalid type for metric: $type"
120 || (
$type === self::TYPE_COUNTER && !is_int(
$value))
122 || (
$type === self::TYPE_TIMESTAMP && !(
$value instanceof \DateTimeImmutable))
123 || (
$type === self::TYPE_TEXT && !is_string(
$value))
124 || (
$type === self::TYPE_COLLECTION && !is_array(
$value))
126 throw new \InvalidArgumentException(
127 "Invalid type " . gettype(
$value) .
" for metric of type $type"
131 if (
$type === self::TYPE_COLLECTION) {
133 if (!($v instanceof
Metric)) {
134 throw new \InvalidArgumentException(
135 "Every element of a collection needs to be a metric, found " . gettype($v)
165 public function toYAML(
int $indentation = 0) : string
182 return sprintf(
"%.03f",
$value);
184 return $value->format(\DateTimeInterface::ISO8601);
186 if (substr_count(
$value,
"\n") > 0) {
187 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
194 function ($k, $v) use ($indentation) {
195 if ($v->getType() === self::TYPE_COLLECTION) {
200 return $this->getIndentation($indentation) .
"$k:$split" . $v->toYAML($indentation + 1);
207 throw new \LogicException(
"Unknown type: " . $this->
getType());
228 return sprintf(
"%.03f",
$value);
230 return $value->format(\DateTimeInterface::ISO8601);
232 if (substr_count(
$value,
"\n") > 0) {
233 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
238 foreach (
$value as $key => $val) {
239 $result[$key] = $val->toArray($indentation + 1);
243 throw new \LogicException(
"Unknown type: " . $this->
getType());
250 while ($indentation--) {
265 throw new \LogicException(
"Can not extract by mixed.");
269 return [$this,
null];
271 if ($this->
getType() !== self::TYPE_COLLECTION) {
272 return [
null, $this];
279 foreach ($values as $k => $v) {
289 if (count($extracted)) {
292 self::TYPE_COLLECTION,
303 self::TYPE_COLLECTION,
311 return [$extracted,
$rest];
317 $sub =
$f->panel()->sub(
"",
$f->legacy(
"<pre>" . $yaml .
"</pre>"));
318 return $f->panel()->report(
$name, [$sub]);
An exception for terminatinating execution or to throw for unit testing.
A metric is something we can measure about the system.
getIndentation(int $indentation=0)
toYAML(int $indentation=0)
checkStability($stability, $type)
checkValue($type, $value)
extractByStability(string $stability)
The extracted part will be the first entry of the array, the second will be the rest of the metrics.
__construct(string $stability, string $type, $value, string $description=null)
toArray(int $indentation=0)
const TYPE_BOOL
The type of the metric tells what to expect of the values.
toUIReport(Factory $f, string $name)
const STABILITY_CONFIG
The stability of a metric tells how often we expect changes in the metric.
This describes how a Report could be modified during construction of UI.
This is how the factory for UI elements looks.
foreach($_POST as $key=> $value) $res