2017 © Pedro Peláez
 

library validate

Validation library for testing primitive and complex types against a contract

image

dsheiko/validate

Validation library for testing primitive and complex types against a contract

  • Wednesday, February 7, 2018
  • by dsheiko
  • Repository
  • 1 Watchers
  • 7 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

Dsheiko\Validate

Latest Stable Version Total Downloads License Build Status, (*1)

Extendable validation library for testing primitive and complex types (including key-value arrays) against a contract, (*2)

Installation

Require as a composer dependency:, (*3)

``` bash composer require "dsheiko/validate", (*4)


## Highlights - Validators are dead simple to extend - It's really easy to validate precondition/postcondition contracts - Validator assertions are directly accessible - Validation of nested arrays ## Usage - [Basic Usage](./wiki/basic-usage.md) - [Provided Validators](./wiki/validators.md) - [Validator Chain](./wiki/validator-chain.md) - [Validation by Contract](./wiki/validation-by-contract.md) - [Map Validation](./wiki/map-validation.md) - [Custom Validators](./wiki/validator-interface.md) ## Examples ### Design by Contract ```php <?php use \Dsheiko\Validate; function login($email, $password) { Validate::contract([ "email" => [ $email, "IsEmailAddress" ], "password" => [ $password, [ "IsString"=> [ "minLength" => 6, "maxLength" => 32, "notEmpty" => true ] ] ], ]); // do login }

may throw, (*5)

  • Dsheiko\Validate\IsString\Exception
  • Dsheiko\Validate\IsString\minLength\Exception
  • Dsheiko\Validate\IsString\maxLength\Exception
  • Dsheiko\Validate\IsEmail\Exception

with a message like, (*6)

  • Parameter "email" validation failed: "jon#snow.i.." is not a valid email address
  • Parameter "password" validation failed: "123" is too short; must be more than 6 chars

Map Validation

<?php

$params = [
  "email" => "jon#snow.io",
  "password" => "******",
];

Validate::map($params, [
    "email" => ["mandatory", "IsEmailAddress"],
    "password" => ["mandatory", "IsString" => ["minLength" => 6, "maxLength" => 128]],
    "rememberMe" => ["optional", "IsBool" ],
]);

Exception messages look like:, (*7)

  • Property "email" validation failed: "jon#snow.i.." is not a valid email address

The Versions

07/02 2018

dev-master

9999999-dev

Validation library for testing primitive and complex types against a contract

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

library validation validate dbc

07/02 2018

v1.1.0

1.1.0.0

Validation library for testing primitive and complex types against a contract

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

library validation validate dbc

11/12 2017

v1.0.1

1.0.1.0

Validation library for testing primitive and complex types against a contract

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

validation validate dbc

08/12 2017

v1.0.0

1.0.0.0

Validation library for testing complex types against a contract

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

validation validate dbc