Download the PHP package aegisora/emptiness-rule-guardian without Composer
On this page you can find all versions of the php package aegisora/emptiness-rule-guardian. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aegisora/emptiness-rule-guardian
More information about aegisora/emptiness-rule-guardian
Files in aegisora/emptiness-rule-guardian
Package emptiness-rule-guardian
Short Description Emptiness Rule Guardian provides a simple shortcut for emptiness validation using aegisora/guardian and aegisora/emptiness-rule
License MIT
Homepage https://github.com/Aegisora/emptiness-rule-guardian
Informations about the package emptiness-rule-guardian
Aegisora Emptiness Rule Guardian
Emptiness Rule Guardian provides a simple shortcut for emptiness validation using aegisora/guardian and aegisora/emptiness-rule.
It is designed for cases where you want to quickly check whether a value is empty or is not empty, without manually building an EmptyRule / NotEmptyRule and a validation pipeline by hand.
This package is built on top of:
โจ Features
- ๐น Simple shortcut API for
EmptyRuleandNotEmptyRule - ๐น Validates that a value is empty via
checkEmpty() - ๐น Validates that a value is not empty via
checkNotEmpty() - ๐น Works with scalars, arrays and countable objects
- ๐น Uses
aegisora/guardianinternally - ๐น Uses
aegisora/emptiness-ruleinternally - ๐น Supports a custom validation exception
- ๐น Keeps rule execution errors separated from validation errors
- ๐น Fully compatible with the Aegisora ecosystem
- ๐น Ready to use out of the box
๐ฆ Installation
๐ Core Concept
This package wraps the common emptiness validation flow:
into a dedicated shortcut class:
Instead of manually creating an EmptyRule / NotEmptyRule and passing it to Guardian, you can use EmptinessRuleGuardian directly.
๐๏ธ Basic Usage
checkEmpty() passes when $value is empty, and fails otherwise.
checkNotEmpty() passes when $value is not empty, and fails otherwise.
โ How the emptiness check works
A value is considered empty when it is null, an empty string, an empty array or an empty countable object.
Every other value โ including 0, 0.0, false and non-countable objects โ is considered not empty:
checkNotEmpty() is the exact inverse โ it passes for every value listed above as fails and fails for every value listed as passes.
โ ๏ธ A
resourcecannot be evaluated for emptiness. Passing a resource raises aGuardianExecutingRuleException(see below) instead of a validation result.
๐งฉ Usage with Custom Exception
You may provide your own exception for validation failure. It must be the last argument.
If the value is empty, the provided exception will be thrown instead of GuardianValidationException.
This is useful when validation errors should have domain-specific meaning.
๐งช Example in Application Service
๐จ Exceptions
The package raises validation-related exceptions, all delegated to Guardian (the outcome of running the rule):
GuardianValidationException
Thrown when validation fails and no custom exception is provided.
The rule code for a failed checkEmpty() is empty_rule, and for a failed checkNotEmpty() it is not_empty_rule.
Custom exception
When a custom exception is passed as the last argument, it is thrown instead of GuardianValidationException on validation failure.
GuardianExecutingRuleException
Thrown when the underlying rule fails to execute (raises a RuleException during validation), as opposed to simply reporting an invalid result.
Emptiness cannot be determined for a resource, so passing a resource surfaces this exception instead of a validation result:
๐งฉ API
EmptinessRuleGuardian::checkEmpty()
Validates that $value is empty.
EmptinessRuleGuardian::checkNotEmpty()
Validates that $value is not empty.
Arguments (both methods):
$valueโ the value to validate$exceptionโ an optional custom\Throwableto be thrown on validation failure
The methods return void. They communicate results through exceptions only โ they return nothing on success and throw on failure:
GuardianValidationExceptionโ the emptiness check failed and no custom exception was provided- the provided custom exception โ the check failed and a custom exception was passed
GuardianExecutingRuleExceptionโ the rule could not be executed
๐๏ธ Architecture
This package is a small shortcut layer over the Aegisora validation pipeline.
Flow:
EmptinessRuleGuardian::checkEmpty()/checkNotEmpty()is called with a value and an optional exception- An
EmptyRule/NotEmptyRuleis created (create()) Guardianexecutes the rule against the value- If the check passes, execution continues normally
- If the check fails, the custom exception or
GuardianValidationExceptionis thrown - If the rule could not be executed,
GuardianExecutingRuleExceptionis thrown
Internal flow:
๐ Related Packages
- aegisora/guardian โ validation execution orchestrator
- aegisora/emptiness-rule โ empty and not empty rules
- aegisora/rule-contract โ base rule contract and validation result architecture
โ๏ธ 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.