Files
fil/docs/snippets/php/plugins/plugin_validator.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

1.2 KiB

<?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";