dev-master
9999999-devPHP validation library.
MIT
The Development Requires
by Romain Cottard
1.0.0
1.0.0.0PHP validation library.
MIT
The Development Requires
by Romain Cottard
PHP validation library.
Validation Component, (*2)
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'); //...
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 require "eureka/component-validation", (*6)
You can install the component (for testing) with the following command:, (*7)
make install
You can update the component (for testing) with the following command:, (*8)
make update
You can test the component with the following commands:, (*9)
make phpcs make tests make testdox
PHP validation library.
MIT
PHP validation library.
MIT