Oihana PHP System

InstanceOfRule extends Rule

Ensures that a given value is instance of the specified class name.

Example:

$rule = new InstanceOfRule(DateTime::class);
$rule->check(new DateTime()) ; // true
$rule->check(new stdClass()) ; // false
Tags
author

Marc Alcaraz (ekameleon)

since
1.0.0

Table of Contents

Constants

CLASS_NAME  = 'className'
The "className" parameter key.
NAME  = 'instanceOf'
The rule name.

Properties

$fillableParams  : array<string|int, mixed>|array<string|int, string>
$message  : string
The error message used when validation fails.

Methods

__construct()  : mixed
Creates a new InstanceOfRule instance.
check()  : bool
Checks if the provided value is an instance of the configured class name.
className()  : static
Sets the class name to check instances against.

Constants

CLASS_NAME

The "className" parameter key.

public mixed CLASS_NAME = 'className'

Properties

$fillableParams

protected array<string|int, mixed>|array<string|int, string> $fillableParams = [self::CLASS_NAME]

The list of required parameters.

$message

The error message used when validation fails.

protected string $message = ":attribute must be an instanceof :className"

Methods

__construct()

Creates a new InstanceOfRule instance.

public __construct([string|null $className = null ]) : mixed
Parameters
$className : string|null = null

The class name expression to evaluate.

check()

Checks if the provided value is an instance of the configured class name.

public check(mixed $value) : bool
Parameters
$value : mixed

The value to check.

Tags
throws
ParameterException

If the required parameter className is missing.

Return values
bool

Returns true if the value is an instance of the specified class; otherwise, false.

className()

Sets the class name to check instances against.

public className(string|null $value) : static
Parameters
$value : string|null

The fully qualified class name.

Return values
static

Returns the current instance for fluent chaining.


        
On this page

Search results