respect-validation/docs/validators/KeyExists.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

2.7 KiB

KeyExists

  • KeyExists(string|int $key)

Validates if the given key exists in an array.

v::keyExists('name')->assert(['name' => 'The Respect Panda']);
// Validation passes successfully

v::keyExists('name')->assert(['email' => 'therespectpanda@gmail.com']);
// → `.name` must be present

v::keyExists(0)->assert(['a', 'b', 'c']);
// Validation passes successfully

v::keyExists(4)->assert(['a', 'b', 'c']);
// → `.4` must be present

v::keyExists('username')->assert(new ArrayObject(['username' => 'therespectpanda']));
// Validation passes successfully

v::keyExists(5)->assert(new ArrayObject(['a', 'b', 'c']));
// → `.5` must be present

Notes

  • To validate an array against a given validator if the key exists, use KeyOptional instead.
  • To validate an array against a given validator requiring the key to exist, use Key instead.

Templates

KeyExists::TEMPLATE_STANDARD

Mode Template
default {{subject}} must be present
inverted {{subject}} must not be present

Template placeholders

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

Caveats

KeyExists defines the given $key as the path, and because it is a standalone validator without children, it's not possible to display a fully custom name with it.

When no custom name is set, the path is displayed as {{name}}. When a custom name is set, the validation engine prepends the path to the custom name:

v::keyExists('foo')->assert([]);
// → `.foo` must be present

v::named('Custom name', v::keyExists('foo'))->assert([]);
// → `.foo` (<- Custom name) must be present

If you want to display only a custom name while checking if a key exists, use Key with AlwaysValid:

v::key('foo', v::named('Custom name', v::alwaysValid()))->assert([]);
// → Custom name must be present

Categorization

  • Arrays
  • Structures

Changelog

Version Description
3.0.0 Created from Key

See Also