Skip to content

Commit

Permalink
PluginOutput: Limit length to 1000 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
nilmerg committed Mar 22, 2024
1 parent a034449 commit 9c325d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions library/Icingadb/Util/PluginOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline-standard.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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

-
Expand Down

0 comments on commit 9c325d0

Please sign in to comment.