CkSanitizerException
What CkSanitizer throws — only when asked.
Raised by CkSanitizer::Html called with
throwIfInvalid: true when neither the value nor the fallback can be used. Never thrown
otherwise: by default the method answers '' instead. Final, and derived from
CkException.
The message names the method, shows the value with its type, says what it was meant to be and why it failed:
CkSanitizer.Html: cannot use "<script>alert(1)</script>" (String) as safe markup — nothing left once the markup is cleaned.
Properties
Every property is public readonly.
| Property | Type | What it holds |
|---|---|---|
Expected |
string |
What the value was meant to be — 'safe markup'. |
Input |
mixed |
From CkException: the value that failed, untouched. |
Reason |
string |
From CkException: why, in a few words. |
Quick look
use SafeCoder\CommonKit\CkSanitizer;
use SafeCoder\CommonKit\Exceptions\CkSanitizerException;
try {
CkSanitizer::Html(
input: '<script>alert(1)</script>',
throwIfInvalid: true
);
} catch (CkSanitizerException $error) {
echo $error->Reason; // -> 'nothing left once the markup is cleaned'
echo $error->Expected; // -> 'safe markup'
}