2017 © Pedro Peláez
 

library can

Tool for easy and powerful data validations

image

carlosv2/can

Tool for easy and powerful data validations

  • Tuesday, July 25, 2017
  • by carlosV2
  • Repository
  • 2 Watchers
  • 2 Stars
  • 516 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 121 % Grown

The README.md

Can

Tool for easy and powerful data validations., (*1)

License Build Status SensioLabsInsight, (*2)

Why

Imagine I give you this data:, (*3)

$data = [
    'key1' => 123,
    'key2' => 'abc',
    'key3' => true
];

And then I ask you to validate it according to the following constraints:, (*4)

  • It must be an array.
  • key1 must contain an integer between 100 and 200.
  • key2 must contain a non-empty string.
  • key3 must contain either a boolean or a callable.
  • If key4 is set, it must be an array with a maximum of 3 items.
  • It cannot have any other key.

How long would your code to validate $data be?, (*5)

Using this project, it can be validated with this code:, (*6)

can($data)->claim(To::beArray()
    ->withKey('key1')->expected(To::beInteger()->withMin(100)->withMax(200))
    ->withKey('key2')->expected(To::beString()->withMinLength(1))
    ->withKey('key3')->expected(To::beOneOf(To::beBoolean(), To::beCallable()))
    ->withKey('key4')->expected(To::beOptionalAnd(To::beArray()->withMaxCount(3)))
    ->withNoOtherKeys()
);

Install

Open a command console, enter your project directory and execute the following command to download the latest stable version of this project:, (*7)

$ composer require carlosv2/can

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*8)

Documentation

Available documentation:, (*9)

The Versions

25/07 2017

dev-master

9999999-dev

Tool for easy and powerful data validations

  Sources   Download

MIT

The Requires

  • php ~5.4 || ~7.0

 

The Development Requires

by Carlos Ortega

validate data extensible can

25/07 2017

1.4.1

1.4.1.0

Tool for easy and powerful data validations

  Sources   Download

MIT

The Requires

  • php ~5.4 || ~7.0

 

The Development Requires

by Carlos Ortega

validate data extensible can

28/06 2017

1.4.0

1.4.0.0

Tool for easy and powerful data validations

  Sources   Download

MIT

The Requires

  • php >=5.4,<7.1

 

The Development Requires

by Carlos Ortega

validate data extensible can

23/06 2017

1.3.0

1.3.0.0

Tool for easy and powerful data validations

  Sources   Download

MIT

The Requires

  • php >=5.4,<7.1

 

The Development Requires

by Carlos Ortega

validate data extensible can

22/06 2017

1.2.0

1.2.0.0

Tool for easy and powerful data validations

  Sources   Download

MIT

The Requires

  • php >=5.4,<7.1

 

The Development Requires

by Carlos Ortega

validate data extensible can

13/06 2017

1.1.0

1.1.0.0

Tool for easy and powerful data validations

  Sources   Download

MIT

The Requires

  • php >=5.4,<7.1

 

The Development Requires

by Carlos Ortega

validate data extensible can

28/05 2016

1.0.0

1.0.0.0

Tool for easy and powerful data validations

  Sources   Download

MIT

The Requires

  • php >=5.4,<7.1

 

The Development Requires

by Carlos Ortega

validate data extensible can