PHP code example of alcidesrc / severe

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

    

alcidesrc / severe example snippets


use Severe\TypeString;
use Severe\TypeBoolean;
use Severe\TypeNull;

$string = TypeString::set($var);
$bool = TypeBoolean::set($flag);
$null = TypeNull::set($optional);
...

$value = $string();
$flag = $bool();
$optional = $null();
...

use Severe\Enums\Currency;

$currency = Currency::EUR;				
echo $currency->value;       // EUR
echo $currency->code();      // 978
echo $currency->name();      // Euro
echo $currency->decimals();  // 2

$currency = Currency::UYI;
echo $currency->value;       // UYI
echo $currency->code();      // 940
echo $currency->name();      // Uruguay Peso en Unidades Indexadas (URUIURUI)
echo $currency->decimals();  // 0

// Dynamic instantiation
$currency = Currency::from('TRY');
echo $currency->value;       // TRY
echo $currency->code();      // 949
echo $currency->name();      // Turkish Lira
echo $currency->decimals();  // 2

use Severe\Enums\Currency;
use Severe\TypeFloat;
use Severe\TypeMoney;

$money = TypeMoney::set(123.456, 'eur');
$money = TypeMoney::set(123.456, Currency::EUR);
$money = TypeMoney::set(TypeFloat::set(123.456), 'EUR');
$money = TypeMoney::set(TypeFloat::set(123.456), Currency::EUR);

[$amount, $currency] = $money();

// $amount is an instance of TypeFloat
// $currency is an instance of Currency

$money = TypeMoney::set(123.456789, 'EUR');
[$amount, $currency] = $money();
echo $amount();                  // 123.46
echo $currency->value;           // EUR

$money = TypeMoney::set(123.456789, 'CLF');
echo $money()[0]->__invoke();    // 123.4568
echo $money()[1]->decimals();    // 4