PHP code example of comos / drapper

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

    

comos / drapper example snippets


$fileContents = file_get_contents('alex.json');
if (!fileContents === false) {
    //report the error
}
$data = json_decode($fileContents, true);
if (!is_array($data)) {
    //report the error
}
$gender = isset($data['gender']) ? $data['gender'] : 'private';

use Comos\Drapper\Bean;
$data = ['id'=>3, 'name'=>'alex'];
Bean::fromArray($data)->int('id');

use Comos\Drapper\Bean;

$defaultValue = 0.1;
$data = ['r0' => 0.2];
$bean = Bean::fromArray($data);
$r0 = $bean->float('r0', '');