bd-validation-rule

Add pure attribute-based validation rules to the BetterData library.

21|1|Updated Apr 29, 2026
One-click install
npx skills add https://github.com/Lonsdale201/wp-agent-skills --skill bd-validation-rule
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: bd-validation-rule
Source: https://github.com/Lonsdale201/wp-agent-skills/tree/main/better-data/bd-validation-rule
Command: npx skills add https://github.com/Lonsdale201/wp-agent-skills --skill bd-validation-rule

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Enforces the addition of new, pure validation rules to BetterData by implementing the Rule interface and decorating data objects with #[Rule] attributes, ensuring rules remain predictable and composable.

Core Features & Use Cases

  • Pure, attribute-based rules that implement the Rule contract.
  • Automatic null handling: rules skip null values unless paired with #[Required].
  • Use Case: introduce a new rule to enforce a specific data format on a DTO field.

Quick Start

Create a new PHP class implementing BetterData\Validation\Rule, add a #[Rule] attribute, and wire it into the validation system.

Frequently Asked Questions about bd-validation-rule

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add custom validation rules to a PHP data object using attributes?

To add custom validation rules to a PHP data object, create a final readonly class implementing the Rule interface and apply it as a pure attribute on your DTO fields.

How does null value handling work in pure attribute-based validation rules?

Pure attribute-based validation rules automatically skip null values unless the field is explicitly paired with a Required attribute, ensuring rules remain predictable.

What interface contract must a new PHP validation rule implement?

A new PHP validation rule must implement the contract public function check(mixed $value, string $fieldName, DataObject $subject): ?string, returning a short error message.

Can I map custom validation rules to a JSON Schema?

Yes, custom validation rules can optionally map to JSON Schema through RestSchemaBuilder when extending the validation system with new Rule classes.

Why should validation rules use final readonly classes in PHP?

Validation rules require final readonly classes to enforce predictable, composable behavior and prevent state modification during the data object validation process.