azly/kphp_validator

v0.0.1 2022-12-18 22:38 UTC

This package is auto-updated.

Last update: 2024-06-12 00:13:52 UTC


README

KPHP Validator

Implemented functions

You can use following constraints for validate data if you want compile your project with KPHP:

Length($min ::: int = -1, $max ::: int = -1, $exact ::: int = -1);
Type($type ::: string);
NotBlank();
Email();

Installation

To install this library, follow these steps:

  1. Download KPHP source code
git clone https://github.com/VKCOM/kphp
  1. Download KPHP Validator library
composer require azly/kphp_validator:dev-master
  1. Compile KPHP from source files

Quick start

  1. Create vendor/autoload.php with composer

  2. Create index.php and write here:

<?php
require_once __DIR__ . '/vendor/autoload.php';

// Create a list with constraints
$ConstraintListFactory = new ConstraintListFactory();

// Create a validator
$validatorFactory = new ValidatorFactory();

// Example of create a constarints
$constraintList->addConstraint("name", new Type("string"));
$constraintList->addConstraint("email", new Email());

// Validation
$validator->validate($form, $constraintList);