-
Notifications
You must be signed in to change notification settings - Fork 1
Bump container contract to 1.1.*, add CLAUDE.md file #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+105
−10
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
db6177b
Add CLAUDE.md file
borkweb b3a96c6
Chore: require container-contract ^1.1 instead of pinning 1.0.4
estevao90 d6e311b
Merge pull request #23 from stellarwp/fix/relax-container-contract-co…
nikolaystrikhar cabdfcd
Chore: rename CLAUDE.md to AGENTS.md with CLAUDE.md symlink
nikolaystrikhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| AGENTS.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.