You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rename Core\Reducer to Composite and expose it as a public validator
The term "Reducer" is widely used in functional programming to describe
a specific pattern: a function that takes an accumulator and a value,
returning a new accumulator (e.g., array_reduce, Redux reducers). This
class does not perform that operation. Instead, it consolidates multiple
validators into a single one, which is the definition of composition.
The new name "Composite" accurately reflects what this validator does:
it composes zero or more validators into a unified validation unit. This
aligns with the Composite design pattern terminology and avoids semantic
confusion with functional programming concepts.
The class has also been moved from the internal Core namespace to the
public Validators namespace. This change acknowledges that composing
validators dynamically is a legitimate use case for library consumers,
not just an internal implementation detail. The library itself uses this
pattern in Attributes and KeySet validators, demonstrating its practical
value.
The signature has been extended to accept zero or more validators:
- Zero validators: Returns AlwaysValid (useful for conditional chains)
- One validator: Pass-through without wrapping (avoids unnecessary nesting)
- Multiple validators: Combines using AllOf (all must pass)
This flexibility is particularly useful when building validation chains
dynamically, where the number of validators may vary at runtime based on
configuration or user input.
Apart from that, we consolidaded the `LogicalComposite` as a composite
that would accept at least two validators. The shifted the logic from
`AllOf` to the `Composite`, and made the `LogicalComposite` extends the
`Composite`, so other classes can leverage the same logic.
Co-authored-by: Alexandre Gomes Gaigalas <alganet@gmail.com>
Assisted-by: Claude Code (Claude Opus 4.5)
Consolidates zero or more validators into a single validator.
12
+
13
+
- When no validators are provided, it acts as [AlwaysValid](AlwaysValid.md).
14
+
- When a single validator is provided, it acts as a pass-through.
15
+
- When multiple validators are provided, they are combined using [AllOf](AllOf.md), meaning all validators must pass for the input to be considered valid.
0 commit comments