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
-**Shared:**`NumericConstraintsTrait` (min, max, multipleOf, etc.); `PipelineType` enum; variant enums `IpVersion`, `Base64Variant`, `UuidVariant` for format methods
21
21
-**String formats:** email, URL, UUID, IP, hostname, domain, time, base64, hex, regex, datetime, date
22
-
-**Schema validation:** AssociativeValidator/ObjectValidator with nested error aggregation
22
+
-**Schema validation:** AssociativeValidator/ObjectValidator with nested error aggregation; shared `SchemaValidatorOptionsTrait` (`coerceAll`, `passthrough`, schema clone helper); `passthrough()` keeps undeclared keys/properties (unvalidated); default output is schema keys only
23
23
-**Logical combinators:**`Validator::allOf`, `anyOf`, `not`; instance `satisfiesAny`, `satisfiesAll`, `satisfiesNone`; `const()` for single allowed value; `enum()` for BackedEnum
24
24
-**Behavior:** Optional by default (null allowed unless `required()`); form-safe coercion (empty string → null, not 0/false); pipeline order guaranteed; fail-fast per field; `satisfies()` accepts validators or callables with `(value, key, input)`; extend via `satisfies()`, not custom validators
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
5
5
## [Unreleased]
6
6
7
+
### Added
8
+
9
+
-`passthrough()` on `AssociativeValidator` and `ObjectValidator`: copy undeclared keys or public properties from the input to the validated output without validating them; declared schema fields are still validated; values already written from the schema (including `outputKey` targets) are not overwritten by passthrough
-**Results accurately reflect the validated data** without unexpected properties
194
+
-**Results accurately reflect the validated data** without unexpected properties (unless you opt into `passthrough()` below)
194
195
-**Default values are consistently applied** when fields are missing
195
196
-**Required field validation still works** (missing required fields cause validation to fail)
196
197
198
+
### Passthrough (undeclared keys)
199
+
200
+
Call `passthrough()` on a schema-backed `Validator::isAssociative()` or `Validator::isObject()` to **copy input keys that are not declared in the schema** onto the validated output **without validating them**. Declared fields are still run through their validators. Values already written from the schema (including keys produced by `outputKey()`) are **not** overwritten by passthrough.
201
+
202
+
Passthrough runs only after all schema fields validate successfully. Copied values are shallow: nested arrays or objects are not recursively validated.
203
+
204
+
```php
205
+
$schema = Validator::isAssociative([
206
+
'name' => Validator::isString()->required(),
207
+
])->passthrough();
208
+
209
+
$input = [
210
+
'name' => 'Ann',
211
+
'metadata' => ['any' => 'structure'],
212
+
'version' => 1,
213
+
];
214
+
215
+
$result = $schema->validate($input);
216
+
// Result includes name (validated) plus metadata and version (copied as-is)
217
+
```
218
+
219
+
With an **empty schema**, `passthrough()` keeps the entire map (still subject to array/object type rules and coercion on the container itself). That pattern is useful for optional opaque payloads such as API metadata:
coerceAll(): static // Recursively enables coercion on schema fields
151
+
passthrough(): static // Copy undeclared keys/properties from input to output without validating them; schema fields still validated; does not overwrite keys already set from the schema (including outputKey targets)
151
152
```
152
153
154
+
By default, outputs only schema-defined keys (plus defaults). With `passthrough()`, any input key not in the schema is copied through unchanged (shallow); nested structures are not recursively validated. For `ObjectValidator`, only **public** properties from the input object are considered (via `get_object_vars()`).
0 commit comments