2017 © Pedro Peláez
 

library component-validation

PHP validation library.

image

eureka/component-validation

PHP validation library.

  • Friday, June 8, 2018
  • by velkuns
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

component-validation

Current version Supported PHP version CI Quality Gate Status Coverage, (*1)

Validation Component, (*2)

Usage

Validator Factory

Validation component use php native filter_var() to validate contents. Please refer to Validate filters and filter_var() for more information about options & flags., (*3)

<?php

use Eureka\Component\Validation\ValidatorFactory;

$factory = new ValidatorFactory();

$string = 'message';

$validatedString = $factory->getValidator('string')->validate($string);
$validatedEmail  = $factory->getValidator('email')->validate('test@example.com');
//...

Generic Entity

Validation component could be used to validate form. But to avoid set an invalid domain entity (a domain Entity should always be complete and valid), you can use generic entity factory., (*4)

This factory can create a pseudo entity with auto validation, and create or update a domain Entity only if the generic entity is valid., (*5)

<?php

use Eureka\Component\Validation\Entity\ValidatorEntityFactory;
use Eureka\Component\Validation\ValidatorFactory;
use Eureka\Component\Validation\Validator\IntegerValidator;

//~ Key as formatted in PascalCase in generic entity
$formData = [
    'userId'     => 1,
    'userName'   => 'Romain',
    'user_email' => 'test@example.com',
    'IsEnabled'  => true,
];

//~ Key as formatted in PascalCase in generic entity also for the config 
$validatorConfig = [
    'user_id'   => ['type' => 'integer', 'options' => IntegerValidator::INT_UNSIGNED],
    'UserEmail' => ['type' => 'email'],
];

$entityFactory = new ValidatorEntityFactory(new ValidatorFactory());
$formEntity = $entityFactory->createGeneric($validatorConfig, $formData);

if (!$formEntity->isValid()) {
    throw new \RuntimeException(implode("\n", $formEntity->getErrors()));
}

$user = new User();
$user->setId($formEntity->getUserId());
$user->setName($formEntity->getUserName());
$user->setEmail($formEntity->getUserEmail());
$user->setIsEnabled($formEntity->isEnabled());

// and persist user in database

Composer

composer require "eureka/component-validation", (*6)

Installation

You can install the component (for testing) with the following command:, (*7)

make install

Update

You can update the component (for testing) with the following command:, (*8)

make update

Testing

You can test the component with the following commands:, (*9)

make phpcs
make tests
make testdox

The Versions

08/06 2018

dev-master

9999999-dev

PHP validation library.

  Sources   Download

MIT

The Development Requires

by Romain Cottard

07/06 2018

1.0.0

1.0.0.0

PHP validation library.

  Sources   Download

MIT

The Development Requires

by Romain Cottard