2017 © Pedro Peláez
 

library validator

A simple validator helper for PS7 requests

image

lefuturiste/validator

A simple validator helper for PS7 requests

  • Wednesday, December 20, 2017
  • by lefuturiste
  • Repository
  • 0 Watchers
  • 0 Stars
  • 186 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 86 % Grown

The README.md

Validator

Continuous integration, (*1)

Simple php validator helper for PSR7 request., (*2)

How to use ?

From PSR-7

$validator = new Validator($request->getParsedBody());

From php input

$validator = new Validator($_POST);

Validate methods (or rules)

$validator->required('example');
$validator->notEmpty('example');

And more validate methods (or rules)..., (*3)

Known if the input is valid

$validator->isValid(); // TRUE|FALSE

Get errors

To get the list of all the errors that your input have you can use the getErrors() method which return all the errors as an array:, (*4)

$validator->getErrors();

You can get errors in a different format, with the rules as key:, (*5)

$validator->getErrors(\Validator\ValidationError::FORMAT_WITH_KEYS);

Or as a array of array, with each array representing an error with the key 'code' and 'message' (format to use in an JSON:API compliant API):, (*6)

$validator->getErrors(\Validator\ValidationError::FORMAT_ARRAY);

If you dont' want to specify each time the ValidationError format you can use this static call to set as a setting for the whole project. For example if you want to set the FORMAT_ARRAY as the default format for the whole project you can use this piece of code:, (*7)

\Validator\ValidationError::setDefaultFormat(\Validator\ValidationError::FORMAT_ARRAY);

I18n

English, french and spanish are supported, (*8)

ValidationLanguage::setLang('fr'); // or `en` or `es`

Tests

All the tests are in the tests folder. You can run tests with theses commands (do a composer install before)., (*9)

  • With composer: composer run test or composer run tests
  • On linux/mac: vendor/bin/phpunit tests
  • On windows: vendor/bin/phpunit.bat tests

The Versions

20/12 2017

dev-master

9999999-dev

A simple validator helper for PS7 requests

  Sources   Download

MIT

The Development Requires

by Avatar lefuturiste

20/12 2017

1.0.5

1.0.5.0

A simple validator helper for PS7 requests

  Sources   Download

MIT

The Development Requires

by Avatar lefuturiste

22/10 2017

1.0.4

1.0.4.0

A simple validator helper for PS7 requests

  Sources   Download

MIT

The Development Requires

by Avatar lefuturiste

08/10 2017

1.0.3

1.0.3.0

A simple validator helper for PS7 requests

  Sources   Download

MIT

The Development Requires

by Avatar lefuturiste

08/10 2017

1.0.2

1.0.2.0

A simple validator helper for PS7 requests

  Sources   Download

MIT

The Development Requires

by Avatar lefuturiste

08/10 2017

1.0.1

1.0.1.0

A simple validator helper for PS7 requests

  Sources   Download

MIT

The Development Requires

by Avatar lefuturiste

16/09 2017

1.0.0

1.0.0.0

A simple validator helper for PS7 requests

  Sources   Download

MIT

by Avatar lefuturiste

16/09 2017

0.0.1.1

0.0.1.1

A simple validator helper for PS7 requests

  Sources   Download

MIT

by Avatar lefuturiste

16/09 2017

0.0.1

0.0.1.0

A simple validator helper for PS7 requests

  Sources   Download

MIT

by Avatar lefuturiste