From db6177b7c74ae7eb46bbaa6c7640cb71318b4fcb Mon Sep 17 00:00:00 2001 From: Matthew Batchelder Date: Tue, 24 Jun 2025 17:02:35 -0400 Subject: [PATCH 1/3] Add CLAUDE.md file --- CLAUDE.md | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..6cbfdde --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,94 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Commands + +### Development +```bash +# Install dependencies +composer install + +# Run static analysis +composer phpstan + +# Generate PHPStan baseline for new violations +composer phpstan:baseline + +# Run tests locally (requires vendor directory) +vendor/bin/codecept run unit + +# Run specific test +vendor/bin/codecept run unit ValidatorTest.php + +# Run tests with SLIC (if available) +slic use validation +slic composer install --ignore-platform-reqs +slic run unit --ext DotReporter +``` + +## Architecture Overview + +### Core Components + +1. **Config** (`src/Config.php`): Static configuration manager + - Must call `Config::setServiceContainer()` before use + - Initialize with `Config::initialize()` to register rules + +2. **Validator** (`src/Validator.php`): Main validation engine + - Takes rules array, values array, and labels array + - Key methods: `passes()`, `fails()`, `validated()`, `errors()` + - Returns sanitized data via `validated()` + +3. **ValidationRulesRegistrar**: Rule registry accessed via service container + - Prevents duplicate rule registration + - Maps rule IDs to class implementations + +### Design Patterns + +- **Strategy Pattern**: Each rule implements `ValidationRule` interface +- **Command Pattern**: Rules can return `ExcludeValue` or `SkipValidationRules` commands +- **Abstract Factory**: Rules created from strings via `fromString()` method +- **Registry Pattern**: Rules registered in `ValidationRulesRegistrar` +- **Trait**: `HasValidationRules` adds validation to value objects + +### Rule System + +Rules can be specified as: +- Strings: `'required'`, `'max:255'`, `'email'` +- Instances: `new Max(255)`, `new Required()` +- Closures: Custom validation logic + +Built-in rule categories: +- Basic: Required, Optional, Nullable, Exclude +- Type: Boolean, Integer, Numeric, Email, Currency, DateTime +- Comparison: Min, Max, Size, In, InStrict +- Conditional: ExcludeIf, NullableIf, OptionalIf (with Unless variants) + +### Key Interfaces + +- `ValidationRule`: Core rule interface with `__invoke()` method +- `Sanitizer`: Rules that modify values during validation +- `ValidatesOnFrontEnd`: Rules that can serialize to JSON for client-side validation +- `ConditionalRule`: Abstract base for conditional validation rules + +### WordPress Integration + +- Uses `__()` for internationalization with `%TEXTDOMAIN%` placeholder +- Hook system via configurable prefix: `{prefix}register_validation_rules` +- Compatible with WordPress coding standards and PHPStan WordPress rules + +### Testing + +Tests use custom assertions in `TestCase`: +- `assertValidationRulePassed($rule, $value, $values = [])` +- `assertValidationRuleFailed($rule, $value, $values = [])` + +Mock rules available for testing validators (e.g., `MockRequiredRule`). + +### Extension Points + +1. Create custom rules by implementing `ValidationRule` +2. Register rules via WordPress action hook +3. Custom exceptions via `Config::setValidationExceptionClass()` +4. Extend `ConditionalRule` for conditional validation logic \ No newline at end of file From b3a96c620033b9ae4ebea2463ad44ee5086830fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Costa?= Date: Wed, 26 Aug 2026 15:57:02 -0300 Subject: [PATCH 2/3] Chore: require container-contract ^1.1 instead of pinning 1.0.4 --- composer.json | 2 +- composer.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 7dd17fa..0a372e9 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ } ], "require": { - "stellarwp/container-contract": "1.0.4", + "stellarwp/container-contract": "^1.1", "stellarwp/field-conditions": "^1.0", "ext-json": "*" }, diff --git a/composer.lock b/composer.lock index c0f19ea..d5d2b83 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e030b86c9bdc981348f98418ad2c2e39", + "content-hash": "ee814cdb497681f9806c6063373aa72b", "packages": [ { "name": "stellarwp/container-contract", - "version": "1.0.4", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/stellarwp/container-contract.git", - "reference": "37becc9edbecb0ff95556048337600dd9cc888f0" + "reference": "ea6e93c95ddf95bbefaa0b6bc529f63ebdb1a8f1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/stellarwp/container-contract/zipball/37becc9edbecb0ff95556048337600dd9cc888f0", - "reference": "37becc9edbecb0ff95556048337600dd9cc888f0", + "url": "https://api.github.com/repos/stellarwp/container-contract/zipball/ea6e93c95ddf95bbefaa0b6bc529f63ebdb1a8f1", + "reference": "ea6e93c95ddf95bbefaa0b6bc529f63ebdb1a8f1", "shasum": "" }, "require": { @@ -49,9 +49,9 @@ ], "support": { "issues": "https://github.com/stellarwp/container-contract/issues", - "source": "https://github.com/stellarwp/container-contract/tree/1.0.4" + "source": "https://github.com/stellarwp/container-contract/tree/1.1.2" }, - "time": "2022-12-20T21:29:17+00:00" + "time": "2026-06-04T17:17:02+00:00" }, { "name": "stellarwp/field-conditions", @@ -5427,7 +5427,7 @@ }, "platform-dev": {}, "platform-overrides": { - "php": "7.2" + "php": "7.4" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } From cabdfcd62c3045806cd5609aec86301e5bd71169 Mon Sep 17 00:00:00 2001 From: Nikolay Strikhar Date: Thu, 27 Aug 2026 13:27:59 +0200 Subject: [PATCH 3/3] Chore: rename CLAUDE.md to AGENTS.md with CLAUDE.md symlink --- AGENTS.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ CLAUDE.md | 95 +------------------------------------------------------ 2 files changed, 95 insertions(+), 94 deletions(-) create mode 100644 AGENTS.md mode change 100644 => 120000 CLAUDE.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..9c6a7e0 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,94 @@ +# AGENTS.md + +This file provides guidance to AI coding agents when working with code in this repository. + +## Commands + +### Development +```bash +# Install dependencies +composer install + +# Run static analysis +composer phpstan + +# Generate PHPStan baseline for new violations +composer phpstan:baseline + +# Run tests locally (requires vendor directory) +vendor/bin/codecept run unit + +# Run specific test +vendor/bin/codecept run unit ValidatorTest.php + +# Run tests with SLIC (if available) +slic use validation +slic composer install --ignore-platform-reqs +slic run unit --ext DotReporter +``` + +## Architecture Overview + +### Core Components + +1. **Config** (`src/Config.php`): Static configuration manager + - Must call `Config::setServiceContainer()` before use + - Initialize with `Config::initialize()` to register rules + +2. **Validator** (`src/Validator.php`): Main validation engine + - Takes rules array, values array, and labels array + - Key methods: `passes()`, `fails()`, `validated()`, `errors()` + - Returns sanitized data via `validated()` + +3. **ValidationRulesRegistrar**: Rule registry accessed via service container + - Prevents duplicate rule registration + - Maps rule IDs to class implementations + +### Design Patterns + +- **Strategy Pattern**: Each rule implements `ValidationRule` interface +- **Command Pattern**: Rules can return `ExcludeValue` or `SkipValidationRules` commands +- **Abstract Factory**: Rules created from strings via `fromString()` method +- **Registry Pattern**: Rules registered in `ValidationRulesRegistrar` +- **Trait**: `HasValidationRules` adds validation to value objects + +### Rule System + +Rules can be specified as: +- Strings: `'required'`, `'max:255'`, `'email'` +- Instances: `new Max(255)`, `new Required()` +- Closures: Custom validation logic + +Built-in rule categories: +- Basic: Required, Optional, Nullable, Exclude +- Type: Boolean, Integer, Numeric, Email, Currency, DateTime +- Comparison: Min, Max, Size, In, InStrict +- Conditional: ExcludeIf, NullableIf, OptionalIf (with Unless variants) + +### Key Interfaces + +- `ValidationRule`: Core rule interface with `__invoke()` method +- `Sanitizer`: Rules that modify values during validation +- `ValidatesOnFrontEnd`: Rules that can serialize to JSON for client-side validation +- `ConditionalRule`: Abstract base for conditional validation rules + +### WordPress Integration + +- Uses `__()` for internationalization with `%TEXTDOMAIN%` placeholder +- Hook system via configurable prefix: `{prefix}register_validation_rules` +- Compatible with WordPress coding standards and PHPStan WordPress rules + +### Testing + +Tests use custom assertions in `TestCase`: +- `assertValidationRulePassed($rule, $value, $values = [])` +- `assertValidationRuleFailed($rule, $value, $values = [])` + +Mock rules available for testing validators (e.g., `MockRequiredRule`). + +### Extension Points + +1. Create custom rules by implementing `ValidationRule` +2. Register rules via WordPress action hook +3. Custom exceptions via `Config::setValidationExceptionClass()` +4. Extend `ConditionalRule` for conditional validation logic \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index 6cbfdde..0000000 --- a/CLAUDE.md +++ /dev/null @@ -1,94 +0,0 @@ -# CLAUDE.md - -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. - -## Commands - -### Development -```bash -# Install dependencies -composer install - -# Run static analysis -composer phpstan - -# Generate PHPStan baseline for new violations -composer phpstan:baseline - -# Run tests locally (requires vendor directory) -vendor/bin/codecept run unit - -# Run specific test -vendor/bin/codecept run unit ValidatorTest.php - -# Run tests with SLIC (if available) -slic use validation -slic composer install --ignore-platform-reqs -slic run unit --ext DotReporter -``` - -## Architecture Overview - -### Core Components - -1. **Config** (`src/Config.php`): Static configuration manager - - Must call `Config::setServiceContainer()` before use - - Initialize with `Config::initialize()` to register rules - -2. **Validator** (`src/Validator.php`): Main validation engine - - Takes rules array, values array, and labels array - - Key methods: `passes()`, `fails()`, `validated()`, `errors()` - - Returns sanitized data via `validated()` - -3. **ValidationRulesRegistrar**: Rule registry accessed via service container - - Prevents duplicate rule registration - - Maps rule IDs to class implementations - -### Design Patterns - -- **Strategy Pattern**: Each rule implements `ValidationRule` interface -- **Command Pattern**: Rules can return `ExcludeValue` or `SkipValidationRules` commands -- **Abstract Factory**: Rules created from strings via `fromString()` method -- **Registry Pattern**: Rules registered in `ValidationRulesRegistrar` -- **Trait**: `HasValidationRules` adds validation to value objects - -### Rule System - -Rules can be specified as: -- Strings: `'required'`, `'max:255'`, `'email'` -- Instances: `new Max(255)`, `new Required()` -- Closures: Custom validation logic - -Built-in rule categories: -- Basic: Required, Optional, Nullable, Exclude -- Type: Boolean, Integer, Numeric, Email, Currency, DateTime -- Comparison: Min, Max, Size, In, InStrict -- Conditional: ExcludeIf, NullableIf, OptionalIf (with Unless variants) - -### Key Interfaces - -- `ValidationRule`: Core rule interface with `__invoke()` method -- `Sanitizer`: Rules that modify values during validation -- `ValidatesOnFrontEnd`: Rules that can serialize to JSON for client-side validation -- `ConditionalRule`: Abstract base for conditional validation rules - -### WordPress Integration - -- Uses `__()` for internationalization with `%TEXTDOMAIN%` placeholder -- Hook system via configurable prefix: `{prefix}register_validation_rules` -- Compatible with WordPress coding standards and PHPStan WordPress rules - -### Testing - -Tests use custom assertions in `TestCase`: -- `assertValidationRulePassed($rule, $value, $values = [])` -- `assertValidationRuleFailed($rule, $value, $values = [])` - -Mock rules available for testing validators (e.g., `MockRequiredRule`). - -### Extension Points - -1. Create custom rules by implementing `ValidationRule` -2. Register rules via WordPress action hook -3. Custom exceptions via `Config::setValidationExceptionClass()` -4. Extend `ConditionalRule` for conditional validation logic \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md new file mode 120000 index 0000000..47dc3e3 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +AGENTS.md \ No newline at end of file