respect-validation/docs/validators/Factory.md
Henrique Moody 7db3bea8a6
Enhance LintSpdxCommand with contributor tracking and header normalization
Improves SPDX header linting to ensure consistent license metadata across
the codebase.

Key changes:

- Enforce deterministic tag ordering (License-Identifier, FileCopyrightText,
  FileContributor) to ensure consistency, prevent merge conflicts, and
  simplify code reviews

- Add contributor alias mapping to consolidate contributors with multiple
  emails or name variations (e.g., "nickl-" → "Nick Lombard")

- Add --contributions-strategy option with "blame" (current code authors)
  and "log" (all historical contributors) to support different attribution
  philosophies

- Add optional path argument to lint specific files or directories

- Add --fix option to automatically correct header issues

Assisted-by: Claude Code (claude-opus-4-5-20251101)
2026-02-03 15:23:20 +01:00

1.8 KiB
Raw Blame History

Factory

  • Factory(callable(mixed): Validator $factory)

Validates the input using a validator that is created from a callback.

v::factory(static fn($input) => v::boolVal())->assert(true);
// Validation passes successfully

This validator is particularly useful when creating validators that rely on the input. A good example is validating whether a confirmation field matches the password field when processing data from a form.

v::key('confirmation', v::equals($_POST['password'] ?? null))->assert($_POST);
// → `.confirmation` must be present

The issue with the code is that its hard to reuse because youre relying upon the input itself ($_POST). That means you can create a chain of validators and use it everywhere.

The factory() validator makes this job much simpler and more elegantly:

v::factory(static fn($input) => v::key('confirmation', v::equals($input['password'] ?? null)))->assert($_POST);
// → `.confirmation` must be present

The code above is similar to the first example, but the biggest difference is that the creation of the validator doesn't rely on the input itself ($_POST), but it will use any input thats given to the validator

Templates

Template placeholders

Placeholder Description
subject The validated input or the custom validator name (if specified).

Categorization

  • Callables
  • Nesting

Changelog

Version Description
3.0.0 Created from KeyValue

See Also