53 lines
1.2 KiB
Markdown
53 lines
1.2 KiB
Markdown
|
|
```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";
|
||
|
|
```
|