Download the PHP package aegisora/regex-rule without Composer
On this page you can find all versions of the php package aegisora/regex-rule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/regex-rule
More information about aegisora/regex-rule
Files in aegisora/regex-rule
Package regex-rule
Short Description Regex Rule provides a simple, rule-based regular expression validation implementation for the Aegisora ecosystem
License MIT
Homepage https://github.com/Aegisora/regex-rule
Informations about the package regex-rule
Aegisora Regex Rule
Regex Rule provides a simple, rule-based regular expression validation implementation for the Aegisora ecosystem.
It is built on top of aegisora/rule-contract and follows its strict validation architecture, ensuring consistent and predictable behavior across applications.
This rule is useful for validating user input, form fields, usernames, slugs, email addresses, phone numbers, API request parameters, and any other string that must match a specific pattern.
๐ Table of Contents
- Features
- Installation
- Core Concept
- Basic Usage
- Valid vs Invalid
- Validation Result
- Guardian Usage
- Real-World Examples
- Factory Methods
- Architecture
- License
- Contributing
- Support
โจ Features
- ๐น Lightweight and dependency-free except
aegisora/rule-contract - ๐น Validates a string against any PCRE regular expression
- ๐น Supports the full pattern syntax and flags (
i,u,m,s, ...) - ๐น Rejects non-string input as an invalid context
- ๐น Surfaces broken patterns and runtime PCRE failures as execution errors instead of a silent
false - ๐น Fully compatible with Aegisora validation pipeline
- ๐น Strict
ContextโResultvalidation flow - ๐น No raw booleans โ only structured results
- ๐น Safe execution via base
Ruleabstraction - ๐น Expressive factory API
- ๐น Ready to use out of the box
๐ฆ Installation
๐ Core Concept
This package implements a single validation rule:
- accepts a string value via
Context - checks whether the string matches the configured regular expression
- returns a standardized
Result
Under the hood it wraps the common boilerplate:
into a reusable rule that reports its outcome through a Result object instead of a raw boolean, and turns PCRE failures into explicit exceptions.
๐๏ธ Basic Usage
The rule can also be instantiated directly:
โ Valid vs Invalid
The rule passes when the string matches the configured pattern and fails otherwise.
Anchored patterns
Unanchored patterns
Flags
๐งช Validation Result
If the string matches the pattern, the rule returns a valid result.
$result->isValid(); // true
If the string does not match the pattern, the rule returns an invalid result.
If the context value is not a string, the rule throws:
Aegisora\RuleContract\Exceptions\InvalidRuleContextException
If the pattern is invalid, or the match fails at runtime (e.g. the backtrack limit is exceeded or the subject is not valid UTF-8 under the u flag), the rule throws:
Aegisora\RuleContract\Exceptions\RuleExecutionException
๐ Guardian Usage
This rule can be used together with aegisora/guardian to build fluent validation pipelines.
If the value does not match the pattern, Guardian throws the provided domain exception.
๐งญ Real-World Examples
Regex Rule is useful for enforcing format constraints before values are persisted or processed.
Examples
๐งฉ Factory Methods
RegexRule::create($pattern);
- creates a rule that passes when the value matches the PCRE
$pattern(delimiters and flags included)
new RegexRule($pattern);
- equivalent to
RegexRule::create($pattern)
RegexRule::create($pattern)->validate($context);
$contextโContextwrapping the string value to validate
๐๏ธ Architecture
This package relies on aegisora/rule-contract.
Flow:
validate()is calledContextis passed in- The configured pattern is checked; a broken pattern raises
RuleExecutionException - The string value is extracted from context (non-strings raise
InvalidRuleContextException) - The value is matched against the pattern with
preg_match(); a PCRE runtime failure raisesRuleExecutionException Resultis returned โ valid on match, invalid with theregex_rulecode on no match
All logic is safely handled by Rule contract.
โ๏ธ License
This package is open-source and licensed under the MIT License. See the LICENSE for details.
๐ฑ Contributing
Contributions are welcome and greatly appreciated! See the CONTRIBUTING for details.
๐ Support
If you find this project useful, please consider giving it a star on GitHub!
It helps the project grow and motivates further development.