Back to Validation

Instance

docs/validators/Instance.md

3.1.11.5 KB
Original Source
<!-- SPDX-License-Identifier: MIT SPDX-FileCopyrightText: (c) Respect Project Contributors SPDX-FileContributor: Alexandre Gomes Gaigalas <[email protected]> SPDX-FileContributor: Henrique Moody <[email protected]> -->

Instance

  • Instance(class-string $class)

Validates if the input is an instance of the given class or interface.

php
v::instance('DateTime')->assert(new DateTime);
// Validation passes successfully

v::instance('Traversable')->assert(new ArrayObject);
// Validation passes successfully

Message template for this validator includes {{instanceName}}.

Templates

Instance::TEMPLATE_STANDARD

ModeTemplate
default{{subject}} must be an instance of {{class|quote}}
inverted{{subject}} must not be an instance of {{class|quote}}

Template placeholders

PlaceholderDescription
class
subjectThe validated input or the custom validator name (if specified).

Categorization

  • Objects

Changelog

VersionDescription
0.3.9Created

See Also