Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Validator Laravel Package

laminas/laminas-validator

Validation component for PHP and Laminas applications. Provides a wide range of ready-to-use validators (strings, numbers, dates, files, and more), consistent error messages, and an extensible API to create custom validators and input filtering rules.

View on GitHub
Deep Wiki
Context7

KeyExists Validator

This validator allows you to validate if a given key is present in an iterable.

Supported Options

The following options are supported for Laminas\Validator\KeyExists:

  • key: Sets the key to be checked. string and int are supported.

Basic Usage

$validator = new Laminas\Validator\KeyExists([
    'key' => 'muppet',
]);

$validInputs = [
    ['muppet' => 'Kermit'],
    new ArrayObject(['muppet' => 'Miss Piggy']),
];

foreach ($validInputs as $input) {
    $result = $validator->isValid($input); // true
}

// Non-exhaustive examples of invalid inputs:
$invalidInputs = [
    'not an array',
    null,
    1,
    'muppet',
];

foreach ($invalidInputs as $input) {
    $result = $validator->isValid($input); // false
}

Integer Keys

PHP casts numeric strings to integers when they are used as array keys:

$array = ['1' => 'Foo'];
// Becomes [1 => 'Foo'];

This validator does the same thing for integer keys:

$validator = new Laminas\Validator\KeyExists([
    'key' => '2',
]);

$validator->isValid(['a', 'b', 'c']); // true

Using a floating point number as a key is not supported because PHP casts floats to integers (And will issue a deprecation on all supported versions of PHP). However, using a string decimal is supported:

$validator = new Laminas\Validator\KeyExists([
    'key' => '1.42',
]);

$validator->isValid(['1.0' => 'a', '1.42' => 'b']); // true

NOTE: Additional Notes Internally the validator calls iterator_to_array on the input to be validated. This may not be desirable if, for example, you are validating a queue where each item is dequeued during iteration, or there are other side effects of iteration on the subject.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core