Download the PHP package aegisora/string-length-rule without Composer
On this page you can find all versions of the php package aegisora/string-length-rule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/string-length-rule
More information about aegisora/string-length-rule
Files in aegisora/string-length-rule
Package string-length-rule
Short Description String Length Rule provides a simple, rule-based string length validation implementation for the Aegisora ecosystem
License MIT
Homepage https://github.com/Aegisora/string-length-rule
Informations about the package string-length-rule
Aegisora String Length Rule
String Length Rule provides a simple, rule-based string length 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, passwords, API request parameters, database column constraints, and any other string that must satisfy a length boundary.
๐ 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 length against a lower bound, an upper bound, or a range
- ๐น Supports strict (
>,<) and inclusive (>=,<=) comparisons - ๐น Counts characters (not bytes) via native
mb_strlen(), so multibyte strings are measured correctly - ๐น Rejects non-string input as an invalid context
- ๐น Fully compatible with Aegisora validation pipeline
- ๐น Strict
ContextโResultvalidation flow - ๐น No raw booleans โ only structured results
- ๐น Safe execution via base
Ruleabstraction - ๐น Expressive factory API for every boundary variation
- ๐น Ready to use out of the box
๐ฆ Installation
๐ Core Concept
This package implements a single validation rule with several factory variations:
- accepts a string value via
Context - checks whether the string length satisfies the configured boundary
- 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.
๐๏ธ Basic Usage
โ Valid vs Invalid
The rule passes when the string length satisfies the configured boundary and fails otherwise. The length is measured in characters via mb_strlen().
Lower bound
Upper bound
Range
๐งช Validation Result
If the length satisfies the boundary, the rule returns a valid result.
$result->isValid(); // true
If the length is out of the boundary, the rule returns an invalid result.
If the context value is not a string, the rule throws:
Aegisora\RuleContract\Exceptions\InvalidRuleContextException
๐ Guardian Usage
This rule can be used together with aegisora/guardian to build fluent validation pipelines.
If the length is out of the allowed boundary, Guardian throws the provided domain exception.
๐งญ Real-World Examples
String Length Rule is useful for enforcing length constraints before values are persisted or processed.
Examples
๐งฉ Factory Methods
StringLengthRule::createGreaterThan($length);
- passes when the string length is strictly greater than
$length
StringLengthRule::createGreaterThanOrEqualTo($length);
- passes when the string length is greater than or equal to
$length
StringLengthRule::createLessThan($length);
- passes when the string length is strictly less than
$length
StringLengthRule::createLessThanOrEqualTo($length);
- passes when the string length is less than or equal to
$length
StringLengthRule::createBetween($min, $max);
- passes when the string length is between
$minand$max, both boundaries inclusive ($min <= length <= $max)
StringLengthRule::createBetweenExclusive($min, $max);
- passes when the string length is between
$minand$max, both boundaries exclusive ($min < length < $max)
StringLengthRule::createBetweenMinExclusive($min, $max);
- passes when the string length is between
$min(exclusive) and$max(inclusive) ($min < length <= $max)
StringLengthRule::createBetweenMaxExclusive($min, $max);
- passes when the string length is between
$min(inclusive) and$max(exclusive) ($min <= length < $max)
StringLengthRule::createGreaterThanOrEqualTo($length)->validate($context);
$contextโContextwrapping the string value to validate
๐๏ธ Architecture
This package relies on aegisora/rule-contract.
Flow:
validate()is calledContextis passed in- The string value is extracted from context (non-strings raise
InvalidRuleContextException) - The length is measured with
mb_strlen() - The length is compared against the configured boundary
Resultis returned โ valid on success, invalid with thestring_length_rulecode on failure
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.