Download the PHP package horde/constraint without Composer
On this page you can find all versions of the php package horde/constraint. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download horde/constraint
More information about horde/constraint
Files in horde/constraint
Package constraint
Short Description Modern constraint library with PHP 8.1+ type safety
License BSD-2-Clause
Homepage https://www.horde.org/libraries/Horde_Constraint
Informations about the package constraint
Horde_Constraint
Modern constraint library for evaluating values against rules.
Overview
Horde_Constraint provides a flexible system for building and evaluating constraints (rules) that determine whether values satisfy certain conditions. It's useful for validation, filtering, and conditional logic.
Dual-Stack API:
- PSR-4 Modern API (
Horde\Constraint\*) - PHP 8.1+ with full type safety - PSR-0 Legacy API (
Horde_Constraint_*) - Backward compatible
Installation
Quick Start
Modern API (Recommended)
Legacy API
Available Constraints
Logical Constraints
AllOf - All constraints must pass (AND logic)
AnyOf - Any constraint must pass (OR logic)
Not - Negates another constraint
Comparison Constraints
IsEqual - Checks equality (loose comparison)
IsInstanceOf - Checks if value is instance of a class
IsNull - Checks if value is null
String Constraints
PregMatch - Matches against PCRE regex
Constant Constraints
AlwaysTrue - Always returns true
AlwaysFalse - Always returns false
Usage Examples
Building Complex Rules
Fluent Constraint Building
Filtering with Constraints
Architecture
Interface
All constraints implement:
Compound Constraints
CompoundConstraint is the base for constraints that contain other constraints:
- Accepts variadic constructor:
new AllOf(...$constraints) - Supports fluent
addConstraint()for dynamic building - Automatically flattens nested constraints of the same type
Migration from PSR-0
For Library Users
No changes required - PSR-0 API remains fully functional.
For New Code (Recommended)
Use the modern PSR-4 API:
Class Mapping
| PSR-0 | PSR-4 (Modern) | PSR-4 (BC Alias) |
|---|---|---|
Horde_Constraint |
Horde\Constraint\Constraint |
- |
Horde_Constraint_And |
Horde\Constraint\AllOf |
AndCoupler (deprecated) |
Horde_Constraint_Or |
Horde\Constraint\AnyOf |
OrCoupler (deprecated) |
Horde_Constraint_Coupler |
Horde\Constraint\CompoundConstraint |
Coupler (deprecated) |
Horde_Constraint_AlwaysTrue |
Horde\Constraint\AlwaysTrue |
- |
Horde_Constraint_AlwaysFalse |
Horde\Constraint\AlwaysFalse |
- |
Horde_Constraint_IsEqual |
Horde\Constraint\IsEqual |
- |
Horde_Constraint_IsInstanceOf |
Horde\Constraint\IsInstanceOf |
- |
Horde_Constraint_Null |
Horde\Constraint\IsNull |
- |
Horde_Constraint_Not |
Horde\Constraint\Not |
- |
Horde_Constraint_PregMatch |
Horde\Constraint\PregMatch |
- |
System Requirements
- PHP ^8.1 (PSR-4 API)
- PHP ^7.4 (PSR-0 API, legacy)
Testing
Test Coverage: 40 tests, 68 assertions
Contributing
Contributions are welcome! Please:
- Follow PER-1 coding style for new code
- Add tests for new constraints
- Use Conventional Commits format
- Ensure all tests pass on PHP 8.1+
Changelog
See doc/changelog.yml for version history.
License
BSD-2-Clause - see LICENSE for details.
Links
- Homepage: https://www.horde.org/libraries/Horde_Constraint
- GitHub: https://github.com/horde/Constraint
- Issues: https://github.com/horde/Constraint/issues
- Packagist: https://packagist.org/packages/horde/constraint
Support
- Mailing List: [email protected]
- GitHub Issues: https://github.com/horde/Constraint/issues
Credits
- Original Author: James Pepin
- Lead: Chuck Hagenbuch
- Copyright: 2009-2026 Horde LLC
- License: BSD-2-Clause