This commit is contained in:
52
docs/snippets/php/plugins/plugin_validator.md
Normal file
52
docs/snippets/php/plugins/plugin_validator.md
Normal file
@@ -0,0 +1,52 @@
|
||||
```php title="PHP"
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Kreuzberg\Kreuzberg;
|
||||
|
||||
class ContentQualityValidator implements Validator {
|
||||
private int $minLength = 10;
|
||||
private int $maxLength = 1000000;
|
||||
|
||||
public function name(): string {
|
||||
return "content-quality-validator";
|
||||
}
|
||||
|
||||
public function version(): string {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
public function initialize(): void {
|
||||
// Load validation rules or patterns
|
||||
}
|
||||
|
||||
public function shutdown(): void {
|
||||
// Cleanup resources
|
||||
}
|
||||
|
||||
public function validate(object $result, object $config): void {
|
||||
$contentLength = strlen($result->content);
|
||||
|
||||
if ($contentLength < $this->minLength) {
|
||||
throw new Exception(
|
||||
"Content too short: $contentLength < {$this->minLength} characters"
|
||||
);
|
||||
}
|
||||
|
||||
if ($contentLength > $this->maxLength) {
|
||||
throw new Exception(
|
||||
"Content too long: $contentLength > {$this->maxLength} characters"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function priority(): int {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
|
||||
// Register the validator
|
||||
$validator = new ContentQualityValidator();
|
||||
Kreuzberg::registerValidator($validator);
|
||||
|
||||
echo "Content quality validator registered\n";
|
||||
```
|
||||
Reference in New Issue
Block a user