PHP code example of morningtrain / data-transfer-object-casters

1. Go to this page and download the library: Download morningtrain/data-transfer-object-casters 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/ */

    

morningtrain / data-transfer-object-casters example snippets


class DTO extends DataTransferObject
{
    #[CastWith(BoolCaster::class)]
    public bool $bool;
}

use Morningtrain\DataTransferObjectCasters\Casters\DateCaster;

class DTO extends DataTransferObject
{
    #[CastWith(DateCaster::class, format: 'Y-m-d')]
    public Carbon $date;
}

use Morningtrain\DataTransferObjectCasters\Casters\UppercaseFirstCaster;

class DTO extends DataTransferObject
{
    #[CastWith(UppercaseFirstCaster::class, lower: true)]
    public string $ucFirstString;
}