PHP code example of kubinyete / assertation

1. Go to this page and download the library: Download kubinyete/assertation 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/ */

    

kubinyete / assertation example snippets


$data = '   Spaced   text   ';

// This validation:
$validated = ($data = trim($data)) && strlen($data) > 2;

if (!$validated) {
    throw new UnexpectedValueException('Data is );

$data = Assert::value($data)->rules('null|str;asTrim;asUppercase;asTruncate,100;lgt,1')->get();
// Data can either be null or a string that has a minimum of 1 character and has every character in uppercase
// while limiting the maximum size to 100 characters with a ellipsis cutoff.

$data = Assert::value($data)->rules('null|float|asDecimal')->get();
// Data can either be null, a float or a string with a decimal number (Ex: 123.23).

$data = Assert::value($data)->null()->or()->asUppercase()->asTrim()->in(['HELLO', 'WORLD'])->get();
// Data can either be null or be 'hello' or 'world' with case insensitivity, resulting only in a upper case result.