PHP Tool Kit / Validator
Utilitário para validar valores em variáveis.
Loading...
Searching...
No Matches
Ptk\Validator Namespace Reference

Data Structures

class  Validator

Enumerations

enum  Types { CALLABLE }

Enumeration Type Documentation

◆ Types

enum Types
Enumerator
CALLABLE 

Representa o tipo booleano (verificado com is_bool()).

Exemplo:

(new Validator())->type(Types::BOOL)->validate(true); // true
(new Validator())->type(Types::BOOL)->validate('true'); // false

Representa um valor numérico, seja inteiro, float ou uma string numérica (verificado com is_numeric()).

Exemplo:

(new Validator())->type(Types::NUMERIC)->validate(10); // true
(new Validator())->type(Types::NUMERIC)->validate('1.5'); // true
(new Validator())->type(Types::NUMERIC)->validate('a1'); // false

Representa o tipo inteiro (verificado com is_int()).

Exemplo:

(new Validator())->type(Types::INT)->validate(7); // true
(new Validator())->type(Types::INT)->validate(7.0); // false

Representa o tipo ponto flutuante (verificado com is_float()).

Exemplo:

(new Validator())->type(Types::FLOAT)->validate(1.5); // true
(new Validator())->type(Types::FLOAT)->validate(1); // false

Representa o tipo string (verificado com is_string()).

Exemplo:

(new Validator())->type(Types::STRING)->validate('texto'); // true
(new Validator())->type(Types::STRING)->validate(123); // false

Representa o tipo array (verificado com is_array()).

Exemplo:

(new Validator())->type(Types::ARRAY)->validate([1, 2]); // true
(new Validator())->type(Types::ARRAY)->validate('[]'); // false

Representa o tipo objeto (verificado com is_object()).

Exemplo:

(new Validator())->type(Types::OBJECT)->validate(new stdClass()); // true
(new Validator())->type(Types::OBJECT)->validate('obj'); // false

Representa o tipo resource (verificado com is_resource()).

Exemplo:

$handle = fopen('php://memory', 'r');
(new Validator())->type(Types::RESOURCE)->validate($handle); // true

Representa um valor que pode ser chamado como função/método (verificado com is_callable()).

Exemplo:

(new Validator())->type(Types::CALLABLE)->validate('strlen'); // true
(new Validator())->type(Types::CALLABLE)->validate('nao-existe-function-xyz'); // false

Definition at line 32 of file Types.php.