Weave Code
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

Laminas Validator provides flexible, reusable validation rules for PHP applications. Includes built-in validators, input filtering/validation chains, and tools for validating common data types like emails, URLs, numbers, strings, and more.

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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport