PHP code example of lavibi / popoya

1. Go to this page and download the library: Download lavibi/popoya library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lavibi / popoya example snippets


use Lavibi\Popoya;

$sameValidator = new Popoya\Same();

$sameValidator->setOptions['
    'compared_value' => 5
'];

$sameValidator->isValid(5);


use Lavibi\Popoya;

$sameValidator = new Popoya\Same();

$sameValidator->sameAs(5); // set options compared_value = 5

$sameValidator->isValid(5);

$chainValidator = new Popoya\ValidatorChain();

$chainValidator->addValidator((new Popoya\Same())->setOptions(...));
$chainValidator->addValidator((new Popoya\NotSame())->setOptions(...));

$chainValidator->isValid(5);

$validator = new Popoya\Validator();

$validator->isRequired('username')->maxLenght(20);
$validator->isRequired('password')->lenght(30, 50);
$validator->isOptional('email')->isEmail();
$validator->isOptional('avatar')->isUpload()->isImage();

// PSR7 post request
$validator->isValid(array_merge(
    $request->getParsedBody(),
    $request->getUploadedFiles()
));