PHP code example of componenta / caster

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

    

componenta / caster example snippets


use Componenta\Caster\CasterProvider;

$provider = new CasterProvider();

$int = $provider->provide('int');
$int->cast('42'); // 42

$provider->provide('missing'); // null

$provider->provide('clamp:10,20')->cast(25); // 20.0
$provider->provide('csv_int')->cast('1,2,3'); // [1, 2, 3]

$provider->provide('trim|lower')->cast('  HELLO  '); // hello

$provider->provide('?int|bool')->cast(null); // null
$provider->provide('?int|bool')->cast('1');  // true