From 9c325d00e772fb70b0074c251e3bb56ffa52015c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 22 Mar 2024 11:23:45 +0100 Subject: [PATCH] PluginOutput: Limit length to 1000 by default --- library/Icingadb/Util/PluginOutput.php | 21 +++++++++++++++++++++ phpstan-baseline-standard.neon | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/library/Icingadb/Util/PluginOutput.php b/library/Icingadb/Util/PluginOutput.php index 71d08b131..03055a9ef 100644 --- a/library/Icingadb/Util/PluginOutput.php +++ b/library/Icingadb/Util/PluginOutput.php @@ -64,6 +64,9 @@ class PluginOutput extends HtmlString /** @var bool Whether the output contains HTML */ protected $isHtml; + /** @var int The maximum amount of characters to process */ + protected $characterLimit = 1000; + /** @var bool Whether output will be enriched */ protected $enrichOutput = true; @@ -93,6 +96,20 @@ public function isHtml(): bool return $this->isHtml; } + /** + * Set the maximum amount of characters to process + * + * @param int $limit + * + * @return $this + */ + public function setCharacterLimit(int $limit): self + { + $this->characterLimit = $limit; + + return $this; + } + /** * Set whether the output should be enriched * @@ -185,6 +202,10 @@ public function render() $output = $this->processHtml($output); } + if ($this->characterLimit) { + $output = substr($output, 0, $this->characterLimit); + } + $this->renderedOutput = $output; return $output; diff --git a/phpstan-baseline-standard.neon b/phpstan-baseline-standard.neon index 960709e7e..d9d2d72e0 100644 --- a/phpstan-baseline-standard.neon +++ b/phpstan-baseline-standard.neon @@ -5067,7 +5067,7 @@ parameters: - message: "#^Parameter \\#1 \\$string of function substr expects string, string\\|null given\\.$#" - count: 2 + count: 3 path: library/Icingadb/Util/PluginOutput.php -